python线程和进程的区别
1个回答
展开全部
python的脚本让一个进程中运行两个线程:
import time
import thread
def Ordering(interval):
cnt = 0
while cnt<100:
print '好了,你订餐成功,订餐号码是:%d号 订餐时间是:%s 请在旁边耐心等待\n\n'%(cnt, time.ctime())
time.sleep(interval)
cnt+=1
thread.exit_thread()
def Notice(interval):
cnt = 0
while cnt<100:
print '谁的号码是%d,您的餐好了,过来取一下\n'%(cnt)
time.sleep(interval)
cnt+=1
thread.exit_thread()
def work(): #Use thread.start_new_thread() to create 2 new threads
thread.start_new_thread(Ordering,(1,))
thread.start_new_thread(Notice,(5,))
if __name__=='__main__':
work()
import time
import thread
def Ordering(interval):
cnt = 0
while cnt<100:
print '好了,你订餐成功,订餐号码是:%d号 订餐时间是:%s 请在旁边耐心等待\n\n'%(cnt, time.ctime())
time.sleep(interval)
cnt+=1
thread.exit_thread()
def Notice(interval):
cnt = 0
while cnt<100:
print '谁的号码是%d,您的餐好了,过来取一下\n'%(cnt)
time.sleep(interval)
cnt+=1
thread.exit_thread()
def work(): #Use thread.start_new_thread() to create 2 new threads
thread.start_new_thread(Ordering,(1,))
thread.start_new_thread(Notice,(5,))
if __name__=='__main__':
work()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询