尝试从 wxpython GUI 运行耗时的任务。基本思想是从 GUI 启动长时间任务(按下按钮),然后应该从它更新对话框上的静态文本。
首先,我尝试了一些线程(http://wiki.wxpython.org/LongRunningTasks和许多其他资源),我想使用 Publisher.class 显示消息。进展并不顺利,一两条消息后,GUI 似乎冻结了。
现在我想通过多处理来实现这一点。我的“GUI”类中有这个方法:
def do_update(self, e):
self.txt_updatemsg.SetLabel("Don't stop this \n")
...
pub = Publisher() # i tried also calling directly from dbob object
# Publisher() is a singleton so this must be useless?
pub.subscribe(self.__update_txt_message, ('updatedlg', 'message'))
dbob = dbutils.DBUtils() # DBUtils is the class with 'long time' tasks
dbob.publisher = pub
p = Process(target=self.do_update_process, args=(dbob,))
p.start()
while p.is_alive:
wx.Yield
def do_update_process(self, dbob):
dbob.do_update()
__update_txt_message 是一个简单的函数,用于在对话框中设置静态文本。
问题是:我怎样才能从这个过程中发回一些短信(只是简单的文本,这就是我所需要的)谢谢大家!