# 守护进程: ! ! ! ( 一定是主进程的代码的结束 )
# 子进程会 随着主进程的 代码执行完毕 而结束
import time from multiprocessing import Process # p.terminate() 结束一个子进程 # p.name 当前进程的名字 # p.pid 当前进程的进程号 # p.is_alive() 检验一个进程是否还存在,返回True or False def fn(): while True: print('in 子进程') time.sleep(0.5) def fn1(): print('这里是 fn1') time.sleep(8) print('8m over') if __name__ == '__main__': p = Process(target=fn) p.daemon = True # 设置子进程为守护进程 p.start() p1 = Process(target=fn1).start() i = 0 while i<5: print('in !!!父进程!!!') time.sleep(1) i += 1