wxpython 笔记本面板在线程运行时挂起 [英] wxpython notebook panel hangs when threads are running

查看:33
本文介绍了wxpython 笔记本面板在线程运行时挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 wxpython 开发一个具有 3-4 个笔记本面板的 gui,其中一个面板(主面板)调用另一个名为 abc.py 的 python 脚本.在这个 abc.py 中,我同时运行多个(> 10)个线程.当我点击主面板上的运行按钮时,它会启动 abc.py 脚本的这些并发线程.我在这里面临的问题是我的 wxpython 笔记本在以下时间挂断了:当我点击运行按钮时,所有线程都已加入".在此期间,我无法控制面板上的其他按钮,也无法在面板之间切换.在这段时间里,我的窗户被冻结了.可能是什么问题呢?如果有人可以指导我采取正确的方法来避免这个问题,那么我将非常感激.谢谢..!!!

I am trying to develop a gui using wxpython that has 3-4 notebook panels and one of these panels (master panel) calls another python script called abc.py. In this abc.py i am running several(>10) threads simultaneously. When I hit run button on master panel it starts these simultaneous threads of abc.py script. The problem I am facing here is my wxpython notebook gets hang up for time between: "when I hit run button and upto all the threads are joined". For this period I am not able to control other buttons on my panel nor am i able to switch between panels. My window gets freezed up for this period of time. What could be the problem? If anyone could guide me to proper path to avoid this issue then i will really be very grateful. Thank you..!!!

推荐答案

您还需要包装对 abc.py 的调用(我想是使用 popen)进入线程,否则 GUI 将阻塞.当外部脚本中的进程正在收集其答案时,您必须以线程安全的方式(重要!)将其取回 wxPython.

You will also need to wrap the call to abc.py (with popen, I suppose) into a thread, otherwise the GUI will block. When the process in the external script is collecting its answer, you have to get it back in a thread-safe way (important!) to wxPython.

如果可能的话,更好的方法是从 abc.py 导入并在长时间运行的线程中旋转导入的对象.

A better way would be to import from abc.py, if that is possible and spin the imported objects in the long running thread.

有关如何以线程安全的方式进行回传的说明,请参阅 wxPython wiki.我个人认为最后一个例子最容易理解和实现.

For an explanation how to communicate back thread-safe see the wxPython wiki. I personally find the last example the easiest to understand and implement.

这篇关于wxpython 笔记本面板在线程运行时挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆