Guy Mayo
Guy Mayo

Reputation: 21

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()

Upvotes: 1

Views: 218

Answers (1)

python00b
python00b

Reputation: 123

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

Upvotes: 1

Related Questions