首页 > 解决方案 > 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 上运行它

请帮我解决这个问题。

标签: python-3.xsystemexitpystray

解决方案


推荐阅读