[英]Python multiprocessing Pool.imap throws ValueError: list.remove(x): x not in list
I have a very simple test fixture that instantiate and close a test class 'APMSim' in different threads, the class is not picklable, so I have to use multiprocessing Pool.imap to avoid them being transferred between processes: 我有一个非常简单的测试装置,可以在不同的线程中实例化并关闭测试类“ APMSim”,该类不可腌制,因此我必须使用multiprocessing Pool.imap以避免它们在进程之间转移:
class APMSimFixture(TestCase):
def setUp(self):
self.pool = multiprocessing.Pool()
self.sims = self.pool.imap(
apmSimUp,
range(numCores)
)
def tearDown(self):
self.pool.map(
simDown,
self.sims
)
def test_empty(self):
pass
However, when I run the empty Python unittest I encounter the following error: 但是,当我运行空的Python单元测试时,遇到以下错误:
Error
Traceback (most recent call last):
File "/home/peng/git/datapassport/spookystuff/mav/pyspookystuff_test/mav/__init__.py", line 87, in tearDown
self.sims
File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "/usr/lib/python2.7/multiprocessing/pool.py", line 567, in get
raise self._value
Why this could happen? 为什么会发生这种情况? Is there a fix to this?
有解决办法吗?
multiprocessing
is re-raising an exception from your worker function/child process in the parent process, but it loses the traceback in the transfer from child to parent. multiprocessing
正在从父进程的工作函数/子进程中引发一个异常,但是在从子进程到父进程的传输中它失去了追溯。 Check your worker function, it's that code that's going wrong. 检查您的worker函数,这是代码出了问题。 It might help to take whatever your worker function is and change:
采取任何您的工作人员职能并进行更改可能会有所帮助:
def apmSimUp(...):
... body ...
to: 至:
import traceback
def apmSimUp(...):
try:
... body ...
except:
traceback.print_exc()
raise
This explicitly prints the full, original exception traceback (then lets it propagate normally), so you can see what the real problem is. 这将显式打印完整的原始异常回溯(然后让其正常传播),因此您可以看到真正的问题是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.