标签:start nat xxx div sleep pre bsp process obj
守护主进程
1 import time 2 import multiprocessing 3 """ 4 进程.daemon = True 守护主进程 5 进程.terminate() 在终止主进程之前终止子进程 6 """ 7 def work1(): 8 for i in range(10): 9 print("我是work",i) 10 time.sleep(0.5) 11 12 if __name__ == ‘__main__‘: 13 # 创建一个进程 14 process_obj = multiprocessing.Process(target=work1) 15 # 启动进程 16 process_obj.daemon = True 17 process_obj.start() 18 19 print("woshi XXX") 20 # process_obj.close() 21 time.sleep(2) 22 print("i am over") 23 # 在主进程结束之前终止子进程 24 process_obj.terminate() 25 exit() 26 print("XXXX")
标签:start nat xxx div sleep pre bsp process obj
原文地址:https://www.cnblogs.com/liuxjie/p/11984893.html