Python中threading模块的join函数
来源:互联网 发布:java 实现ll 1 文法 编辑:程序博客网 时间:2024/05/18 21:10
Join的作用是众所周知的,阻塞进程直到线程执行完毕。通用的做法是我们启动一批线程,最后join这些线程结束,例如:
for i in range(10):
t = ThreadTest(i)
thread_arr.append(t)
for i in range(10):
thread_arr[i].start()
for i in range(10):
thread_arr[i].join()
此处join的原理就是依次检验线程池中的线程是否结束,没有结束就阻塞直到线程结束,如果结束则跳转执行下一个线程的join函数。
而py的join函数还有一个特殊的功能就是可以设置超时,如下:
Thread.join([timeout])
Wait until the thread terminates. This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception – or until the optional timeout occurs.
也就是通过传给join一个参数来设置超时,也就是超过指定时间join就不在阻塞进程。而在实际应用测试的时候发现并不是所有的线程在超时时间内都结束的,而是顺序执行检验是否在time_out时间内超时,例如,超时时间设置成2s,前面一个线程在没有完成的情况下,后面线程执行join会从上一个线程结束时间起再设置2s的超时。
- Python中threading模块的join函数
- python的threading模块中threading.RLock和threading.Lock
- Python中Threading.Join的案例解析
- Python的Threading模块的Thread对象的join方法
- Python的threading模块
- python中threading模块详解
- python中threading模块详解
- python中threading模块详解
- python中threading模块详解
- python threading模块的使用
- Python的多线程threading模块
- Python:使用threading模块实现多线程编程三[threading.Thread类的重要函数]
- Python:使用threading模块实现多线程编程三[threading.Thread类的重要函数]
- python threading join
- python中threading模块详解(一)
- python中threading模块详解(一)
- python中threading模块详解(一)
- Python中threading的join和setDaemon的区别及用法[例子]
- go arm、android版本
- Java学习笔记_1_字符的读入
- 全民小镇ios越狱用户叉叉助手辅助刷金币攻略
- 四种加密算法之RSA源代码-C++
- java中静态方法和动态方法的本质区别
- Python中threading模块的join函数
- 四种加密算法之SHA1源代码-C++
- 在ASP.NET中操作文件的例子(VB)
- IOS7 新特性
- 如何实现动态添加Html文档中Form项
- 四种加密算法之DES源代码-C++
- 用FSO获得图片文件的信息(大小,宽,高)
- 微信技术应用2大核心:语音和扫一扫
- 春困夏乏 ,8种食物提神抗疲劳