我有一个需要运行的计算列表。我正在使用它们并行化它们
from pathos.multiprocessing import ProcessingPool
pool = ProcessingPool(nodes=7)
values = pool.map(helperFunction, someArgs)
helperFunction
确实创建了一个名为 的类Parameters
,该类与在同一文件中定义
import otherModule
class Parameters(otherModule.Parameters):
...
到目前为止,一切都很好。helperFunction
会根据Parameters
对象做一些计算,改变它的一些属性,最后使用pickle
. 这是进行保存的辅助函数(来自不同的模块)的相关摘录:
import pickle
import hashlib
import os
class cacheHelper():
def __init__(self, fileName, attr=[], folder='../cache/'):
self.folder = folder
if len(attr) > 0:
attr = self.attrToName(attr)
else:
attr = ''
self.fileNameNaked = fileName
self.fileName = fileName + attr
def write(self, objects):
with open(self.getFile(), 'wb') as output:
for object in objects:
pickle.dump(object, output, pickle.HIGHEST_PROTOCOL)
当它到达时pickle.dump()
,它会引发一个难以调试的异常,因为调试器不会进入实际面临该异常的工作人员。因此,我在转储发生之前创建了一个断点,并手动输入了该命令。这是输出:
>>> pickle.dump(objects[0], output, pickle.HIGHEST_PROTOCOL)
Traceback (most recent call last):
File "/usr/local/anaconda2/envs/myenv2/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2885, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-4d2cbb7c63d1>", line 1, in <module>
pickle.dump(objects[0], output, pickle.HIGHEST_PROTOCOL)
File "/usr/local/anaconda2/envs/myenv2/lib/python2.7/pickle.py", line 1376, in dump
Pickler(file, protocol).dump(obj)
File "/usr/local/anaconda2/envs/myenv2/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/usr/local/anaconda2/envs/myenv2/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/usr/local/anaconda2/envs/myenv2/lib/python2.7/pickle.py", line 396, in save_reduce
save(cls)
File "/usr/local/anaconda2/envs/myenv2/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/local/anaconda2/envs/myenv2/lib/python2.7/site-packages/dill/dill.py", line 1203, in save_type
StockPickler.save_global(pickler, obj)
File "/usr/local/anaconda2/envs/myenv2/lib/python2.7/pickle.py", line 754, in save_global
(obj, module, name))
PicklingError: Can't pickle <class '__main__.Parameters'>: it's not found as __main__.Parameters
helperFunction
奇怪的是,当我不并行化(即手动循环)时,这不会发生。我很确定我打开的是正确的Parameters
(而不是父类)。
我知道如果没有可重现的示例,很难调试事物,我不希望这部分有任何解决方案。也许更普遍的问题是: