python multiprocessing: why is process defunct after terminate?
Asked Answered
P

1

6

I have some python multiprocessing code with the parent process starting a bunch of child worker processes and then terminating them after awhile:

from multiprocessing import Process

nWorkers = 10
curWorkers = []
for iw in range(nWorkers):
    pq = Process(target=worker, args=(worker's_args_here))
    pq.start()
    curWorkers.append(pq)

# Do work here...

for pw in curWorkers:
    pw.terminate()

However, the child processes all are showing as defunct long after termination. Are they zombie processes? More importantly, how should I terminate them so that they really go away?

Parget answered 6/1, 2014 at 22:45 Comment(0)
M
8

Try adding:

for pw in curWorkers:
    pw.join()

at the end. .terminate() just kills the process. The parent process still needs to reap it (at least on Linux-y systems) before the child process goes away entirely.

Mercurate answered 6/1, 2014 at 23:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.