python父线程关闭后子线程不关闭问题
2015-11-17 00:02
627 查看
我们都知道,python可以通过threading module来创建新的线程,然而在创建线程的线程(父线程)关闭之后,相应的子线程可能却没有关闭,这可能是因为代码中没有使用setDaemon(True)函数。接下来,使用一个例子来说明:
我们需要把setDaemon函数放在start函数前面,不然它是不给通过的,并且返回’cannot set daemon status of active thread‘
import threading def prt_hello() : while 1 : print 'hello' if __name__ == '__main__' : t = threading.Thread(target=prt_hello) t.setDaemon(True) t.start()
我们需要把setDaemon函数放在start函数前面,不然它是不给通过的,并且返回’cannot set daemon status of active thread‘
相关文章推荐
- Python神图
- python 关于dict的一些总结
- python 实现 Dijkstra最短路径问题
- wxpython学习2
- Python+opencv 无法正确读取视频文件(已解决)
- 【程序员技术练级】学习一门脚本语言 python(三)跟数据库打交道
- Python特殊语法:filter、map、reduce、lambda
- LeetCode OJ 系列之35 Search Insert Position --Python
- python BeautifulSoup 正则匹配糗事百科并保存到本地
- python下编译py成pyc和pyo
- 升级python
- Python字符串,元组、列表、字典
- 【NumPy学习指南】day4 多维数组的切片和索引
- Python文件I/O
- Python编写微信打飞机小游戏(八)
- Python Web部署方式总结
- python知识索引-数组、矩阵、字典、函数
- 【python】xml Elementtree 学习一
- python的变量传递
- python之路day4