在运行中结束程序 [英] Ending a Program Mid-Run

查看:97
本文介绍了在运行中结束程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pythoncom.PumpMessages()

据我了解,这一行基本上告诉程序永远等待.对我来说,它似乎正在工作.但是,我希望能够在适当的刺激下结束该程序.如何结束上述行,或停止程序进一步运行.

From what I understand this line basically tells the program to wait forever. For my purposes it seems to be working. However, I'd like to be able to end the program given the right stimulus. How would one go about ending the above line, or stopping the program from running any further.

推荐答案

根据这些 docs pythoncom.PumpMessages():

为当前线程抽取所有消息,直到出现WM_QUIT消息为止.

Pumps all messages for the current thread until a WM_QUIT message.

因此,停止收集消息的一种方法是使用 ctypes 库来调用 PostQuitMessage :

So one way to stop collecting messages is by posting a WM_QUIT message to the message queue by using the ctypes library to call PostQuitMessage:

ctypes.windll.user32.PostQuitMessage(0)

这篇关于在运行中结束程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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