我multiprocessing正在使用模块,我正在使用UpdateMessage对象(我自己的类),通过multiprocessing.Queue对象发送,在进程之间进行通信.这是类:
class UpdateMessage:
def __init__(self, arrayref, rowslice, colslice, newval):
self.arrayref = arrayref
self.rowslice = rowslice
self.colslice = colslice
self.newval = newval
def do_update(self):
if self.arrayref == 'uL':
arr = uL
elif self.arrayref == 'uR':
arr = uR
else:
raise Exception('UpdateMessage.arrayref neither uL nor uR')
arr[self.rowslice, self.colslice] = self.newval
Run Code Online (Sandbox Code Playgroud)
当我运行脚本时,它完全正常.但是,当我使用cProfile或运行它时profile,它会出现以下错误:
_pickle.PicklingError: Can't pickle <class '__main__.UpdateMessage'>: attribute lookup __main__.UpdateMessage failed
Run Code Online (Sandbox Code Playgroud)
它似乎试图挑选课程,但我不明白为什么会发生这种情况.我的代码没有这样做,没有它就可以正常工作,所以它可能就是multiprocessing模块.但为什么需要腌制UpdateMessage,我该如何修复错误呢?
编辑:这是发送的代码的一部分UpdateMessage(脚本的多个部分执行此操作,但所有都以相同的方式):
msg = UpdateMessage(uLref, refer[0] …Run Code Online (Sandbox Code Playgroud)