【Python】守护进程
# 守护进程随主进程结束而终止, 守护进程不可生成新的子进程
from multiprocessing import Process
import time
def task(name):
print('%s is runing' % name)
time.sleep(2)
print('end')
# p = Process(target=task, kwargs={'name': 'child2'})
# AssertionError: daemonic processes are not allowed to have children
# p.start()
if __name__ == '__main__':
p = Process(target=task, kwargs={'name':'child'})
p.daemon = True # 启动前设定
p.start()
p.join()
print('主')