6

我有一些看起来像这样的python代码:

procs = cpu_count()-1
if serial or procs == 1:
    results = map(do_experiment, experiments)
else:
    pool = Pool(processes=procs)     
    results = pool.map(do_experiment, experiments)

当我设置serial标志时它运行良好,但在使用时它会给出以下错误Pool。当我尝试do_experiment从无到有打印某些东西时,我无法尝试/捕捉那里并打印堆栈跟踪。

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 530, in __bootstrap_inner
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 483, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 285, in _handle_tasks
    put(task)
TypeError: 'NoneType' object is not callable

什么是进行调试的好方法?

4

1 回答 1

17

我回到了我的 git 历史,直到我找到了一个仍然有效的提交。

我在我的代码中添加了一个扩展类,dict以便可以使用 a .(所以dict.foo而不是dict["foo"]. Multiprocessing 对此不友好,使用普通 dict 解决了问题。

于 2012-05-31T09:47:54.900 回答