INNER CODE UNIT · Python
instance
pairinteraction/pairinteraction · src/pairinteraction_gui/app.py:39
def instance() -> Application:
"""Return the current instance of the application."""
return QApplication.instance() # type: ignore [return-value]
def allow_ctrl_c(self) -> None:
# Create a pipe to communicate between the signal handler and the Qt event loop
pipe_r, pipe_w = os.pipe()
def signal_handler(signal: int, frame: FrameType | None) -> None:
os.write(pipe_w, b"x") # Write a single byte to the pipe
signal.signal(signal.SIGINT, signal_handler)
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()