【发布时间】:2020-06-06 13:00:31
【问题描述】:
我正在尝试在我的 Python 脚本中实现来自 win32api 的 SetConsoleCtrlHandler,以便在我通过单击 Windows cmd 上的“X”按钮关闭脚本时执行一个函数。
我的问题是 print_test() 在登录后运行导致 open_latest_thread() 不运行,而不是仅在意外退出时运行 print_test()。我在这里做错了吗?
def print_test():
print("test")
login()
win32api.SetConsoleCtrlHandler(print_test(), True)
while True:
try:
open_latest_thread()
except Exception as e:
print(e)
continue
【问题讨论】:
-
我的回答对你有用吗?