如果子进程是一个死循环会怎么办?
- 主进程销毁之前,销毁子进程
- 让子进程守护主进程,主进程销毁子进程销毁,子进程会依赖于子进程。
import multiprocessing
import time
g_list = list()
def rask():
for i in range(1, 10):
g_list.append(i)
time.sleep(0.2)
print(i)
pass
pass
if __name__ == '__main__':
rask_process = multiprocessing.Process(target=rask)
# 方式一:
# rask_process.daemon = True
rask_process.start()
time.sleep(1)
# 方式二;
rask_process.terminate()
print("over")