Create child processes inside a child process with Python multiprocessing failed -
i observed behavior when trying create nested child processes in python. here parent program parent_process.py
:
import multiprocessing import child_process pool = multiprocessing.pool(processes=4) in range(4): pool.apply_async(child_process.run, ()) pool.close() pool.join()
the parent program calls "run" function in following child program child_process.py:
import multiprocessing def run(): pool = multiprocessing.pool(processes=4) print 'test!' pool.close() pool.join()
when run parent program, nothing printed out , program exited quickly. however, if print 'test!'
moved 1 line above (before nested child processes created), 'test!'
printed 4 times.
because errors in child process won't print screen, seems show program crashes when child process creates own nested child processes.
could explain happens behind scene? thanks!
according multiprocessing documentation, daemonic processes cannot spawn child processes.
multiprocessing.pool
uses daemonic processes ensure don't leak when program extits.
Comments
Post a Comment