Python multiprocessing and wxPython working together

谁都会走 提交于 2019-12-24 14:12:21

问题


I've got the following problem:

I've written a script which is running up to four processes at the same time. Works like a charm when using it via command line. Then I made the decision to write a GUI with wxPython and I was quickly figuring out that the GUI and the script need to run in different processes so both stay usable while the other is doing something. (i.e. being able to press a stop button while the script is running) This is also working perfectly.

Now the problem: I just cannot communicate with the GUI while the script is running or at least I have no idea how. I'm trying to write output in a text window by passing "self" (the gui) to the script and in the script I try to do things like "self.outputWindow.WriteText('the script is doing bla 1 of bla 10')"

I even figured out why this won't work: self (the gui object) is not pickable and that's mandatory for multiprocessing, but I don't know how else I should do it.


回答1:


You can use my tutorial on wxPython and threads, although I'm not sure if Python spreads those threads evenly to all the cores. I suspect it doesn't.

Fortunately, there are examples of using the multiprocessing module with wxPython. See the following links:

  • http://wiki.wxpython.org/MultiProcessing
  • wxPython non-blocking GUI threading AND multiprocessing?
  • wxpython GUI and multiprocessing - how to send data back from the long running process
  • http://www.blog.pythonlibrary.org/2012/08/03/python-concurrency-porting-from-a-queue-to-multiprocessing/

I hope those are helpful!



来源:https://stackoverflow.com/questions/16064662/python-multiprocessing-and-wxpython-working-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!