fix: handle SIGINT so Ctrl+C cleanly exits the app

Qt's event loop swallows SIGINT. Add a periodic timer to let Python
process signals and route SIGINT to the clean quit handler.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-02-11 14:50:08 -06:00
parent 53caf193af
commit 0900329020

View File

@ -2,9 +2,10 @@
from __future__ import annotations
import signal
import sys
from PySide6.QtCore import QByteArray
from PySide6.QtCore import QByteArray, QTimer
from PySide6.QtGui import QAction, QIcon
from PySide6.QtNetwork import QLocalServer, QLocalSocket
from PySide6.QtWidgets import QApplication, QMenu, QSystemTrayIcon
@ -141,4 +142,13 @@ class MyMemoryApp:
def run(self) -> int:
"""Run the application event loop."""
self.setup_tray()
# Let Python's SIGINT handler fire inside the Qt event loop.
# A zero-interval timer gives Python a chance to run signal handlers
# between Qt event loop iterations.
timer = QTimer()
timer.start(500)
timer.timeout.connect(lambda: None)
signal.signal(signal.SIGINT, lambda *_: self._quit())
return self._app.exec()