When you create a Pool
of processes using Python's multiprocessing
, those processes will fork and globals in the parent process will show up in the child processes, noted in this question below:
How can I restrict the scope of a multiprocessing process?
This appears to include imported modules. That's a problem for modules that have side effects in __init__
. Tensorflow is one such module, as soon as it's imported it tries to allocate memory to the GPU. This causes the sub process to crash because the parent already took that action.
Is there a good way to avoid the tensorflow module loading in the forked process?
Python 2.7 on Ubuntu (posix)