python multiprocess daemon,pythonmultiprocess,The process’
python multiprocess daemon,pythonmultiprocess,The process’
The process’s daemon flag, a Boolean value. This must be set before start() iscalled.
The initial value is inherited from the creating process.
When a process exits, it attempts to terminate all of its daemonic childprocesses.
Note that a daemonic process is not allowed to create child processes.Otherwise a daemonic process would leave its children orphaned if it getsterminated when its parent process exits. Additionally, these are not Unixdaemons or services, they are normal processes that will be terminated (andnot joined) if non-dameonic processes have exited.
# encoding=utf8'''Created on 2013-3-22@author: corleone'''from multiprocessing import Processimport timefrom uuid import uuid4class TProcess(Process): def __init__(self): Process.__init__(self) def run(self): while 1: time.sleep(1) with open(r'd:\\tprocess', u'a') as f: f.write(u'%s %s \\n' % (self.name,uuid4()))if __name__ == '__main__':#===============================================================================# cmd:main process print '...' after sleep 3 second , and then stop , tprocess stop # eclipse:main process print '...' after sleep 3 second , and then stop , tprocess stop #===============================================================================# try:# t = TProcess()# t.daemon = True# t.start()# time.sleep(3)# print u'...'# except Exception as e:# print u'xxx'# raise e#===============================================================================# cmd:main process print ... , but not stop and tprocess still running# stop main process manually , tprocess stop too , it's the same when t.join() is uncomment# eclipse:main process print ... , but not stop and tprocess still running# stop main process manually , tprocess still running#=============================================================================== try: t = TProcess() t.daemon = False t.start() time.sleep(3) print u'...'# t.join() except Exception as e: print u'xxx' raise e#===============================================================================# cmd:both running,when stop main process manually then tprocess stop # eclipse:both running,when stop main process, tprocess still running #===============================================================================# try:# t = TProcess()# t.daemon = False# t.start()# t.join()# print u'to sleep '# time.sleep(3)# print u'sleep finished'# print u'...'# except Exception as e:# print u'xxx'# raise e#===============================================================================# cmd : both running , when stop main process stop then tprocess stop # eclipse : both running ,main process stop , but tprocess still running #===============================================================================# try:# t = TProcess()# t.daemon = True# t.start()# t.join()# print u'to sleep '# time.sleep(3)# print u'sleep finished'# print u'...'# except Exception as e:# print u'xxx'# raise e#===============================================================================# so in my opinion # daemon means be monitored by the create process or thread passivity# rather than initiative#===============================================================================#该片段来自于http://byrx.net
相关内容
- 猜数游戏,猜数,def caishu()
- 使用BeautifulSoup4修改的百度新歌榜下载脚本,,import ur
- 通过tcp实现字符大写转换的python客户端代码,tcppython
- Python实现的几种排序算法,python排序算法,包括了:冒泡
- python直接修改excel,pythonexcel,import xlrdf
- 显示zip里面的文件列表,显示zip文件列表,def zf(filen
- 自杀脚本,,import os, s
- python实现统计word的小程序,pythonword小程序,Python语言
- python从sqlite读取数据并显示,pythonsqlite读取,import cgi,
- python中id()函数的实用研究实例,python实例,>>>
评论关闭