简体   繁体   中英

What happens to threads that start in process after it ends

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM