交互式 Python 图形用户界面
Python 对我来说真的很坎坷,因为上次我创建 GUI 客户端时,客户端在生成进程、调用 shell 脚本和调用外部应用程序时似乎挂起。
从那时起,这一直是我使用 Python 的主要问题,现在我在一个新项目中,有人可以给我指点和建议,以便我的 GUI python 应用程序在生成另一个进程时仍然具有交互性吗?
Python have been really bumpy for me, because the last time I created a GUI client, the client seems to hang when spawning a process, calling a shell script, and calling outside application.
This have been my major problem with Python since then, and now I'm in a new project, can someone give me pointers, and a word of advice in order for my GUI python application to still be interactive when spawning another process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单(抽象意义上不一定是“最好”):在单独的线程中生成子进程,通过 Queue.Queue 实例将结果传达回主线程 - 主线程必须定期检查该队列以查看结果是否已尚未到达,但在任何事件循环中安排定期轮询并不困难。
Simplest (not necessarily "best" in an abstract sense): spawn the subprocess in a separate thread, communicating results back to the main thread via a Queue.Queue instance -- the main thread must periodically check that queue to see if the results have arrived yet, but periodic polling isn't hard to arrange in any event loop.
如果您生成一个进程并等待它完全完成,您的主 GUI 线程将冻结。通常,您可以简单地使用 subprocess 并时不时地轮询它是否完成,而不是
等待
它完成。这将防止你的 GUI 冻结。Your main GUI thread will freeze if you spawn off a process and wait for it to completely. Often, you can simply use subprocess and poll it now and then for completion rather than
wait
ing for it to finish. This will keep your GUI from freezing.