1 # coding=utf8 2 import multiprocessing 3 import time 4 5 6 def process(name): 7 while True: 8 print('进程名:{}正在运行...'.format(name)) 9 time.sleep(0.2) 10 11 12 if __name__ == '__main__': 13 p1 = multiprocessing.Process(target=process, kwargs={'name': 'p1'}) 14 # 把子进程设置成守护进程,主进程退出,子进程也结束。否则主进程退出,子进程仍然进行 15 # 或者使用p1.terminate()来结束 16 p1.daemon = True # 子进程设置成守护进程 17 p1.start() 18 19 time.sleep(0.5) 20 print('主进程结束了....................')
标签:__,p1,结束,name,python,time,进程 From: https://www.cnblogs.com/zsx-blog/p/16771908.html