I am trying to write tests with nose that get set up with something calculated using multiprocessing.
I have this directory structure:
code/
tests/
tests.py
tests.py looks like this:
import multiprocessing as mp
def f(i):
return i ** 2
pool = mp.Pool()
out = pool.map(f, range(10))
def test_pool():
"""Really simple test that relies on the output of pool.map.
The actual tests are much more complicated, but this is all
that is needed to produce the problem."""
ref_out = map(f, range(10))
assert out == ref_out
if __name__ == '__main__':
test_pool()
Running from the code
directory, python tests/tests.py
passes.
nosetests tests/tests.py
fails to complete. It starts up, but never gets through the call to pool.map
and just hangs.
Why is this and what is the simplest solution?