Python join多线程意义何在,pythonjoin,import threa
Python join多线程意义何在,pythonjoin,import threa
import threadingimport timeclass Producer(threading.Thread): def __init__(self,t_name): threading.Thread.__init__(self,name=t_name) def run(self): global x con.acquire() if x>0: con.wait() else: for i in xrange(0,5,1): x+=1 print u'producing...'+str(x) con.notify() print x con.release()class Consumer(threading.Thread): def __init__(self,t_name): threading.Thread.__init__(self,name=t_name) def run(self): global x con.acquire() if x<0: con.wait() else: for i in xrange(0,5,1): x-=1 print u'consume...'+str(x) con.notify() print x con.release()con = threading.Condition()x = 0print u'start consumer'c = Consumer('consumer')print u'start producer'p = Producer('producer')p.start()c.start()p.join()c.join()print x
最后的join()函数的有无对程序结果并无显示作用?请问join()在这里意义何在?
不join 主线程结束了你的子线程怎么办
Other threads can call a thread’s join() method. This blocks the calling thread until the thread whose join() method is called is terminated.
Thread Objects
threading.Thread.join
阻塞当前调用 thread.join()的进程或者线程,直到join的线程( the thread whose join() method is called )结束,才继续执行当前进程或者线程(the calling thread )~
编橙之家文章,
相关内容
- python有支持内存保存SQL查询依然可用的功能吗,python
- Python xlwt写入单元格并合并单元格操作问题,pythonxlwt
- 让python支持ssl有什么简单方法,python支持ssl方法,我使用
- Python HTMLParse模块能获得嵌套标签里内容吗,pythonhtmlp
- import导入__xxx__.py文件,它的'__name__'是什么,__xxx__.py__
- Python模块相对与绝对导入两种方式的区别是什么,pyt
- Web程序中全局变量python新手不是很理解,全局变量pyt
- Python判断dict中重复值最高效方法是什么,python判断di
- Python Gevent开启猴子补丁后线程阻塞会否影响整个程序,
- 请问Nginx+uwsgi+django后端sock文件丢失解决方法是什么,
评论关闭