noi*_*oio 5 python multithreading stack-trace multiprocessing
我有一些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)
Run Code Online (Sandbox Code Playgroud)
设置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
Run Code Online (Sandbox Code Playgroud)
什么是继续调试的好方法?
noi*_*oio 16
我回到了我的git历史,直到我找到了一个仍在工作的提交.
我在我的代码中添加了一个类,dict以便可以使用a来访问密钥.(因此dict.foo代替dict["foo"].多处理并不需要这样,使用普通的dict解决了问题.
| 归档时间: |
|
| 查看次数: |
1438 次 |
| 最近记录: |