酸洗物体
我需要pickle对象[wxpython框架对象]并将其作为参数发送到多处理池模块上的函数apply_async 有人可以给我举个例子我该怎么做吗 我尝试了以下操作并收到错误消息:
myfile = file(r"C:\binary.dat", "w")
pickle.dump(self, myfile)
myfile.close()
self.my_pool.apply_async(fun,[i,myfile])
def fun(i,self_object):
window = pickle.load(self_oject)
wx.CallAfter(window.LogData, msg)
有人可以告诉我可能是什么问题吗
如果错误在我收到的最后一条错误消息下方给出了一些指示: 文件“C:\Python26\lib\copy_reg.py”,第 70 行,在 _reduce_ex 中 引发 TypeError,“无法腌制 %s 对象” % base.名称 TypeError:无法腌制 PySwigObject 对象
I need to pickle object [wxpython frame object] and send it as a prameter to this function apply_async on multiproccessing pool module
could someone provide me an example how can I do it
I tried the following and get an error message :
myfile = file(r"C:\binary.dat", "w")
pickle.dump(self, myfile)
myfile.close()
self.my_pool.apply_async(fun,[i,myfile])
def fun(i,self_object):
window = pickle.load(self_oject)
wx.CallAfter(window.LogData, msg)
could someone tell me what could be the problem
If the error give some indicator below the last error message i get:
File "C:\Python26\lib\copy_reg.py", line 70, in _reduce_ex
raise TypeError, "can't pickle %s objects" % base.name
TypeError: can't pickle PySwigObject objects
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能序列化小部件以在另一个进程中使用。我猜您想更改由
multiprocessing
模块启动的另一个进程的 GUI 内容。在这种情况下,您应该在父流程中定义一个回调函数,当子流程的结果准备好时调用该函数。因此,您可以使用的“callback”参数apply_async
。像这样的东西:
You can not serialize a widget for use in another process. I guess you want to change the GUI content from another process that is started by the
multiprocessing
module. In that case, you should define a callback function in the parent process that gets called when the result of the sub-process is ready. Therefore you can use the "callback" parameter ofapply_async
.Something like:
我不相信 wxPython 对象可以被 pickle。它们只是 C 对象的包装器,其中包含大量指针和其他有状态的东西。 pickle 模块对它们的了解不够,无法在之后恢复它们的状态。
I don't believe that wxPython objects can be pickled. They are just wrappers around C objects, which contain lots of pointers and other stateful stuff. The pickle module doesn't know enough about them to be able to restore their state afterwards.