I have a Python module that uses multiprocessing
. I'm executing this module from another script with runpy
. However, this results in (1) the module running twice, and (2) the multiprocessing
jobs never finish (the script just hangs).
In my minimal working example, I have a script runpy_test.py:
import runpy
runpy.run_module('module_test')
and a directory module_test containing an empty __init__.py and a __main__.py:
from multiprocessing import Pool
print 'start'
def f(x):
return x*x
pool = Pool()
result = pool.map(f, [1,2,3])
print 'done'
When I run runpy_test.py, I get:
start
start
and the script hangs.
If I remove the pool.map
call (or if I run __main__.py directly, including the pool.map
call), I get:
start
done
I'm running this on Scientific Linux 7.6 in Python 2.7.5.