Pickling objects

前端 未结 2 1076
长发绾君心
长发绾君心 2021-01-28 21:10

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 c

2条回答
  •  死守一世寂寞
    2021-01-28 21:15

    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)
    

提交回复
热议问题