python中threading的setDaemon、join的用法(未完,待续)
来源:互联网 发布:安徽芜湖java 编辑:程序博客网 时间:2024/06/05 22:26
python中得thread的一些机制和C/C++不同:在C/C++中,主线程结束后,其子线程会默认被主线程kill掉。而在python中,主线程结束后,会默认等待子线程结束后,主线程才退出。
- join:如在一个线程B中调用threada.join(),则threada结束后,线程B才会接着threada.join()往后运行。
- setDaemon:主线程A启动了子线程B,调用b.setDaemaon(True),则主线程结束时,会把子线程B也杀死,与C/C++中得默认效果是一样的。
在这里给出一个例子:
<span style="color:#ffffff;"> </span><span style="color:#330033;">1 #! /usr/bin/env python 2 3 import threading 4 import time 5 6 class myThread(threading.Thread): 7 def __init__(self, threadname): 8 threading.Thread.__init__(self, name=threadname) 9 self.st = 2 10 11 def run(self):12 time.sleep(self.st)13 print self.getName()14 def setSt(self, t): 15 self.st = t 16 17 def fun1():18 t1.start()19 print "fun1 done"20 21 def fun2():22 t2.start()23 print "fun2 done"24 25 t1=myThread("t1")26 t2=myThread("t2")27 t2.setSt(10);28 # t2.setDaemon(True)29 fun1()30 fun2()31 print "now u will see me"</span>
0 0
- python中threading的setDaemon、join的用法(未完,待续)
- Python中threading的join和setDaemon的区别及用法[例子]
- Python中threading的join和setDaemon的区别及用法[例子]
- Python中threading的join和setDaemon的区别及用法[例子]
- Python中threading的join和setDaemon的区别及用法[例子]
- Python中threading的join和setDaemon的区别及用法 例子
- python中thread的setDaemon、join的用法
- python中thread的setDaemon、join的用法
- python中thread的setDaemon、join的用法
- python中thread的setDaemon、join的用法
- python中thread的setDaemon、join的用法
- python中thread的setDaemon、join的用法
- python多线程中join和setDaemon的用法
- python多线程编程以及join,setDaemon,线程锁的用法
- threading的应用以及join、setDaemon的分析
- python threading中的join和setDaemon方法
- Python中threading模块的join函数
- Python中Threading.Join的案例解析
- iOS9新特性
- 二分查找的两种实现方式--循环和递归
- 微服务指南走北(二):微服务架构的进程间通信(IPC)
- oracle用户创建及权限设置详解
- 重载(overload)
- python中threading的setDaemon、join的用法(未完,待续)
- 四种方案解决ScrollView嵌套ListView问题
- print2flash实现将word文档转换成swf,网页直接预览
- 文章标题
- No enclosing instance of type 类名 is accessible. Must qualify the allocation with an enclosing instan
- android 常用图片处理效果总结
- 再次领悟设计模式-职责链
- 机器学习入门 之 概论
- 内部类