INNER CODE UNIT · Python
handle_signal
pairinteraction/pairinteraction · src/pairinteraction_gui/app.py:52
def handle_signal() -> None:
os.read(pipe_r, 1) # Read the byte from the pipe to clear it
logger.info("Ctrl+C detected in terminal. Shutting down gracefully...")
self.quit()
sn = QSocketNotifier(pipe_r, QSocketNotifier.Type.Read, parent=self)
sn.activated.connect(handle_signal)
# Create a timer to ensure the event loop processes events regularly
# This makes Ctrl+C work even when the application is idle
timer = QTimer(self)
timer.timeout.connect(lambda: None) # Do nothing, just wake up the event loop
timer.start(200)
@staticmethod
def quit() -> None:
"""Quit the application."""
logger.debug("Calling Application.quit().")