I observed this behavior when trying to create nested child processes in Python. Here is the parent program parent_process.py :
import multiprocessing import child_process pool = multiprocessing.Pool(processes=4) for i in range(4): pool.apply_async(child_process.run, ()) pool.close() pool.join()
The parent program calls the run function in the following child_process.py child program:
import multiprocessing def run(): pool = multiprocessing.Pool(processes=4) print 'TEST!' pool.close() pool.join()
When I run the parent program, nothing was printed, and the program quickly exited. However, if print 'TEST!' moves one line up (before creating nested child processes), 'TEST!' printed 4 times.
Since errors in the child process will not be displayed, this seems to indicate that the program crashes when the child process creates its own nested child processes.
Can someone explain what is going on behind the scenes? Thanks!
python multiprocessing
Da kuang
source share