标签:assert processes erro .com time name start children pre
1.守护进程:
(1)守护进程会在主进程结束的时候立马结束
(2)守护进程要设置在start之前
(3)守护进程能不能再开启子进程,否则会报错。(错误:AssertionError: daemonic processes are not allowed to have children)
代码例子:
from multiprocessing import Process import time def work(name): print(‘task <%s> is runing‘ %name) time.sleep(2) print(‘task <%s> is done‘ % name) if __name__ == ‘__main__‘: p1=Process(target=work,args=(‘egon‘,)) p1.daemon = True #设置p1为守护进程,并且一定要在start之前设置,主进程结束p1立马结束运行。 p1.start() print(‘主进程‘)
执行结果:
标签:assert processes erro .com time name start children pre
原文地址:http://www.cnblogs.com/yxwang/p/7451782.html