[英]What happens to threads that start in process after it ends
https://stackoverflow.com/a/45130246/13121815 https://stackoverflow.com/a/45130246/13121815
In the post above the answer says that you can start threads inside a process but, what happens to the threads if the process ends first, i mean if you remove the join of the threads inside the bar function.在上面的帖子中,答案说您可以在进程内启动线程,但是,如果进程先结束,线程会发生什么,我的意思是如果您删除 bar 函数内线程的连接。
def foo():
print("Thread Executing!")
def bar():
threads = []
for _ in range(3): # each Process creates a number of new Threads
thread = threading.Thread(target=foo)
threads.append(thread)
thread.start()
# for thread in threads:
# thread.join()
if __name__ == "__main__":
processes = []
for _ in range(3):
p = multiprocessing.Process(target=bar) # create a new Process
p.start()
processes.append(p)
for process in processes:
process.join()
The question you are asking is "what happens if a parent process dies before its child process".您要问的问题是“如果父进程在其子进程之前死亡会发生什么”。 The Child becomes a socalled "Orphan Process".子进程成为所谓的“孤儿进程”。 A quick duckduckgo search gave me this: https://linuxjourney.com/lesson/process-termination一个快速的duckduckgo搜索给了我这个: https ://linuxjourney.com/lesson/process-termination
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.