python-3.x - python 中的 sys.exit 给出了 SystemExit 错误
问题描述
我正在运行一个启动控制台程序的 PYSTRAY 图标。当我尝试使用此代码停止它时
def stop_rtd():
print("Stopping RTD")
sys.exit()
icon.stop()
系统抛出此错误
An error occurred when calling message handler
Traceback (most recent call last):
File "C:\Users\ramac\AppData\Local\Programs\Python\Python37\lib\site-packages\pystray\_win32.py", line 389, in _dispatcher
uMsg, lambda w, l: 0)(wParam, lParam) or 0)
File "C:\Users\ramac\AppData\Local\Programs\Python\Python37\lib\site-packages\pystray\_win32.py", line 209, in _on_notify
descriptors[index - 1](self)
File "C:\Users\ramac\AppData\Local\Programs\Python\Python37\lib\site-packages\pystray\_base.py", line 267, in inner
callback(self)
File "C:\Users\ramac\AppData\Local\Programs\Python\Python37\lib\site-packages\pystray\_base.py", line 368, in __call__
return self._action(icon, self)
File "C:\Users\ramac\AppData\Local\Programs\Python\Python37\lib\site-packages\pystray\_base.py", line 463, in wrapper0
return action()
File "C:/Tej/GitHub/Python/YahooDLs/try_systray.py", line 16, in stop_rtd
sys.exit()
SystemExit
RTD 是永久的控制台程序。它停止但图标继续并且控制台没有关闭。关闭控制台时,程序退出并且图标关闭。
我在 Windows10 上运行它
请帮我解决这个问题。
解决方案
推荐阅读
- visual-studio-code - 为什么不能在 IDLE 中安装 pip 但在 vscode 中安装它会使其在空闲状态下工作?
- reactjs - 是否可以在 React 中的静态选项卡名称/文本旁边显示动态计数/数字?
- azure - 如何为不同的 API 使用单独的 Apim-Subscription-Key?
- rust - 存储在闭包内部调用的函数的返回类型
- javascript - 将json对象路径从字符串转换为对象
- java - Selenium 无法打开 Chrome 浏览器
- r - 如何使用 grpreg 包为组套索设置组参数?
- reactjs - Gatsby 的 gatsby-source-filesystem 的动态 graphQL 查询
- javascript - Vue.js 3 - 通过计算属性启用/禁用表单元素
- html - 如何在打印页面时删除 .tab-pane 边框?