[python之daemon线程]

  A thread can be flagged as a “daemon thread”. The significance of this flag is that the entire Python program exits when only daemon threads are left.

  当只剩daemon线程时,程序会退出。

  The initial value is inherited from the creating thread. The flag can be set through the daemon property. Daemon threads are abruptly stopped at shutdown. Their resources (such as open files, database transactions, etc.) may not be released properly. If you want your threads to stop gracefully, make them non-daemonic and use a suitable signalling mechanism such as an Event.

  Function: isDaemon(), setDaemon()
  A boolean value indicating whether this thread is a daemon thread (True) or not (False). This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False. The entire Python program exits when no alive non-daemon threads are left.
  
  要点: 当无活跃的非daemon线程时, 当前python程序会退出. 突然退出的daemon不会释放资源(打开的文件,数据库操作). 所以建议使用非Daemon线程,使用Event这种信号机制来退出程序.
  
  参考官方文档:http://docs.python.org/2.7/library/threading.html#thread-objects

最新文章

  1. corefile 设置
  2. WCF--验证码实现...
  3. BZOJ3424 : Poi2013 Multidrink
  4. POJ 2481 Cows(树状数组)
  5. 使用VS2013在WIN8.1上运行gaclib的hello world
  6. state配置语言实战
  7. Zend Studio GitHub 使用教程
  8. 华硕电脑安装ubuntu出现问题及决方案
  9. 异步编程设计模式 - IronPythonDebugger
  10. Telepro工具注册码
  11. Java开发必须掌握的线上问题排查命令
  12. 《团队-爬虫豆瓣top250项目-团队一阶段互评》
  13. 腾讯开源项目phxpaxos的编译步骤
  14. java正则表达式的忽略大小写
  15. springboot之使用redistemplate优雅地操作redis
  16. 洛谷 P3253 [JLOI2013]删除物品 解题报告
  17. 使用Maven创建(eclipse)Java项目
  18. wordvec_词的相似度
  19. PHP与Java进行通信的实现方法
  20. 008-jdk1.7版本新特性

热门文章

  1. Class.getResource()方法的使用
  2. 流程设计器jQuery + svg/vml(Demo5 - 撤消与重做)
  3. STL标准库-容器-deque
  4. web前端开发常用的几种图片格式及其使用规范
  5. 如何在Oracle官网下载java的JDK最新版本和历史版本
  6. 《FDTD electromagnetic field using MATLAB》读书笔记之一阶、二阶偏导数差商近似
  7. MyBatis_Study_004(动态代理)
  8. POJ 2406Power Strings(KMP)
  9. numpy安装包scipy
  10. ASP.NET MVC基础入门.