酸洗对象 [英] Pickling objects

查看:98
本文介绍了酸洗对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要腌制对象[wxpython frame object]并将其作为参数发送给多处理池模块上的函数apply_async 有人可以给我一个例子,我该怎么做 我尝试了以下操作,并收到一条错误消息:

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

如果错误在最后一条错误消息下方提供了一些指示符,则我得到: _reduce_ex中的文件"C:\ Python26 \ lib \ copy_reg.py",第70行 引发TypeError,无法腌制%s对象"%base.名称 TypeError:无法腌制PySwigObject对象

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

推荐答案

您无法序列化可在另一个进程中使用的窗口小部件.我猜您想从multiprocessing模块启动的另一个进程中更改GUI内容.在这种情况下,您应该在父流程中定义一个回调函数,当子流程的结果准备好时,该回调函数将被调用.因此,您可以使用 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 of apply_async.

类似的东西:

def fun(i):
    # do something in this sub-process and then return a log message
    return "finished doing something"

def cb(resultFromFun):
    wx.CallAfter(window.LogData, resultFromFun)

my_pool.apply_async(fun, [i], callback = cb)

这篇关于酸洗对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆