[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

python之daemon线程的更多相关文章

  1. [Python]Threading.Thread之Daemon线程

    之前对Daemon线程理解有偏差,特记录说明: 一.什么是Daemon A thread can be flagged as a "daemon thread". The sign ...

  2. python学习笔记——线程threading (二)重写run()方法和守护进程daemon()

    1 run()方法 1.1 单个线程 在threading.Thread()类中有run()方法. from time import ctime,sleep import threading # 定义 ...

  3. Python—进程、线程、协程

    一.线程 线程是操作系统能够进行运算调度的最小单位.它被包含在进程之中,是进程中的实际运作单位.一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发多个线程,每条线程并行执行不同的任务 方法: ...

  4. Python进程、线程、协程

    进程和线程的解释 进程(process)和线程(thread)是操作系统的基本概念,计算机的核心是CPU,它承担了所有的计算任务: 单个CPU一次只能运行一个任务,代表单个CPU总是运行一个进程,其他 ...

  5. Python进程和线程

    引入进程和线程的概念及区别 1.线程的基本概念 概念 线程是进程中执行运算的最小单位,是进程中的一个实体,是被系统独立调度和分派的基本单位,线程自己不拥有系统资源,只拥有一点在运行中必不可少的资源,但 ...

  6. python中的线程技术

    #!/user/bin/env python # @Time :2018/7/7 11:42 # @Author :PGIDYSQ #@File :DaemonTest.py import threa ...

  7. python并发_线程

    关于进程的复习: # 管道 # 数据的共享 Manager dict list # 进程池 # cpu个数+1 # ret = map(func,iterable) # 异步 自带close和join ...

  8. Python并发编程-线程

    Python作为一种解释型语言,由于使用了全局解释锁(GIL)的原因,其代码不能同时在多核CPU上并发的运行.这也导致在Python中使用多线程编程并不能实现并发,我们得使用其他的方法在Python中 ...

  9. python进阶之 线程编程

    1.进程回顾 之前已经了解了操作系统中进程的概念,程序并不能单独运行,只有将程序装载到内存中,系统为它分配资源才能运行,而这种执行的程序就称之为进程.程序和进程的区别就在于:程序是指令的集合,它是进程 ...

随机推荐

  1. PLSQL 触发器

    触发器权限 数据库创建用户时想要在本用户下使用触发器,需要给用户触发器的权限 使用DBA用户执行  GRANT CREATE TRIGGER TO user_name; 如果想在当前用户下创建其他用户 ...

  2. Outpost Security Suite Pro 8.1 – 免费4个月

    OSS( 简称 )一款来自俄罗斯Agnitum公司的互联网安全产品. Outpost以网络防火墙知名,AVG和avast!等知名安全企业都有使用Outpost的防火墙技术. Outpost Secur ...

  3. PostgreSQL锁级别及什么操作获取什么锁

    表级锁 大多数的表级锁是由内置的 SQL 命令获得的,但他们也可以通过锁命令来明确获取.可使用的表级锁包括: 访问共享(ACCESS SHARE) - SELECT 命令可在查询中引用的表上获得该锁. ...

  4. 移动端H5调用摄像头(选择上传图片)

    <label>照相机</label> <input type="file" id='image' accept="image/*" ...

  5. Linux系列:Linux中如何安装.rpm、.tar、.tar.gz和tar.bz2文件

    转载自:https://blog.csdn.net/lanxuezaipiao/article/details/21896579 我以下面三个包为例:(三个包都在/etc/opt下) A. examp ...

  6. 【转载】一张表看懂LTE和5G NR的区别

    转自:微信公众号:网优雇佣军 KPI 物理层

  7. 《DSP using MATLAB》示例Example 9.9

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  8. Ext.js 之MVC

    Ext.js 4.0之MVC

  9. windows下php7安装redis扩展

    windows下php7安装redis扩展windows下开发用的wamp集成的环境,想装个php-redis扩展.php_redis.dll下载地址:https://pecl.php.net/pac ...

  10. Oracle本地网络服务名配置

    1.安装Oracle 11G Client后可以在开始菜单中找到 选择NETCA->本地网络服务名配置 选择添加本地网服务名配置 这里的服务名:指的是也就是数据库名 在网络中架设C/S 客户端选 ...