酸洗物体

发布于 2024-09-26 03:02:44 字数 549 浏览 7 评论 0原文

我需要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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彼岸花似海 2024-10-03 03:02:44

您不能序列化小部件以在另一个进程中使用。我猜您想更改由 multiprocessing 模块启动的另一个进程的 GUI 内容。在这种情况下,您应该在父流程中定义一个回调函数,当子流程的结果准备好时调用该函数。因此,您可以使用 的“callback”参数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)

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.

Something like:

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)
谁的年少不轻狂 2024-10-03 03:02:44

我不相信 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文