I have an application that starts subprocesses (currently 64) and does some work. Each process finishes after about 45min but somehow the parent process seems to hung up, because the parent process does not exit and hangs in the join loop.
I start the proccesses like this:
def worker(out_q):
# do something that takes a lot of time
print('done working')
sys.exit(0)
def main():
procs = []
out_q = Queue()
for i in range(opt.num_threads):
sys.stdout.write("\r\tStarting Worker Process: %d" %(i+1))
sys.stdout.flush()
p = multiprocessing.Process(target=worker, args=(out_q,))
procs.append(p)
p.start()
#then i wait for all processes to finish:
try:
for i, p in enumerate(procs):
print("waiting for process %d" %i)
p.join()
print("process %d joined" %i)
except KeyboardInterrupt as e:
sys.exit(0)
if __name__ == "__main__":
main()
the only output i see is waiting for process 0
and after all processes are done (i see all processes saying done working
, there are still all 64 processes in the process list and the parent process does not finish.
It seems that the parent process hung up, because it cant be killed by the task manager.
How can i debug that or do i need to kill the process? why does the process dont get removed from the processlist after calling sys.exit(0) inside the child?