[英]python: start a Multiprocessing process on wxbutton click
I have a wxpython app running, and I was wondering if I could start another instance of the app as a result of a button click when the previous ones continue to run? 我有一个运行的wxpython应用程序,我想知道是否可以在以前的应用程序继续运行时通过单击按钮来启动该应用程序的另一个实例?
something like : Start a wxpython app -> click on a button -> and the event spawns another process (a multiprocessing process) that starts another instance of this same app while the first one keeps on running? 像这样:启动一个wxpython应用程序->单击一个按钮->然后该事件产生另一个进程(一个多处理进程),该进程启动同一应用程序的另一个实例,而第一个实例继续运行?
I just wanted to know whether it is feasible because when I start a simple process inside a button click event handling, like 我只是想知道这是否可行,因为当我在按钮单击事件处理中启动一个简单的过程时,例如
def start_new_button(self,event):
import multiprocessing
worker2 = multiprocessing.Process(name = 'worker2', target = self.new)
worker2.start()
def new():
pass
it throws error 它引发错误
Traceback (most recent call last):
File "main.py", line 470, in start_new_button
worker2.start()
File "C:\Python27\lib\multiprocessing\process.py", line 130, in start
self._popen = Popen(self)
File "C:\Python27\lib\multiprocessing\forking.py", line 277, in __init__
dump(process_obj, to_child, HIGHEST_PROTOCOL)
File "C:\Python27\lib\multiprocessing\forking.py", line 199, in dump
ForkingPickler(file, protocol).dump(obj)
File "C:\Python27\lib\pickle.py", line 224, in dump
self.save(obj)
File "C:\Python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python27\lib\pickle.py", line 419, in save_reduce
save(state)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Python27\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\multiprocessing\forking.py", line 67, in dispatcher
self.save_reduce(obj=obj, *rv)
File "C:\Python27\lib\pickle.py", line 401, in save_reduce
save(args)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 548, in save_tuple
save(element)
File "C:\Python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python27\lib\pickle.py", line 419, in save_reduce
save(state)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Python27\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "C:\Python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python27\lib\pickle.py", line 419, in save_reduce
save(state)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Python27\lib\pickle.py", line 686, in _batch_setitems
save(v)
File "C:\Python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python27\lib\pickle.py", line 396, in save_reduce
save(cls)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 748, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle <type 'PySwigObject'>: it's not found as __bu
iltin__.PySwigObject
C:\Python27\lib\site-packages\mpltools\style\__init__.py:42: FutureWarning:
The style-sheet functionality in mpltools has been integrated into
Matplotlib >= 1.4. This module will be removed in a future release.
Note that style-sheets used by `matplotlib.style` use the standard
Matplotlib rc-file syntax instead of the INI format used by `mpltools`.
This mostly means un-quoting strings and changing '=' to ':'.
""", FutureWarning)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
self = load(from_parent)
File "C:\Python27\lib\pickle.py", line 1378, in load
return Unpickler(file).load()
File "C:\Python27\lib\pickle.py", line 858, in load
dispatch[key](self)
File "C:\Python27\lib\pickle.py", line 880, in load_eof
raise EOFError
EOFError
Am I going on the right path? 我走的路正确吗?
Iam using python 2.7 with wx 3.0.2.0 on windows 7 IAM在Windows 7上将Python 2.7与WX 3.0.2.0结合使用
Python multiprocessing
uses the pickle
module to pass the information to the new process. Python multiprocessing
使用pickle
模块将信息传递给新进程。 The pickle
documentation describes, what can be pickled and unpickled . pickle
文档中描述了可以腌制和不腌制的内容 。 With self.new
you are trying to pass an instance method which cannot be pickled. 使用self.new
您试图传递无法腌制的实例方法。
Try passing a non-instance method to multiprocessing.Process()
: 尝试将非实例方法传递给multiprocessing.Process()
:
class YourButtonClass:
def start_new_button(self,event):
import multiprocessing
worker2 = multiprocessing.Process(name = 'worker2', target = new)
worker2.start()
def new():
pass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.