我正在尝试用鼻子编写测试,这些测试使用使用多处理计算的东西进行设置。
我有这个目录结构:
code/
tests/
tests.py
tests.py 看起来像这样:
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()
从code
目录运行,python tests/tests.py
通过.
nosetests tests/tests.py
未能完成。它启动了,但从来没有通过调用pool.map
而只是挂起。
为什么会这样,最简单的解决方案是什么?