我有一些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
什麼是繼續調試的好方法?
這可能沒有關係,但cpu_count()的返回值是多少? – mgilson
取決於系統,2取決於我自己的筆記本電腦,8取決於服務器,無論哪種方式;如果使用'pool.map' 'map',things break。 – noio