1

I presume closing a terminal window (or a terminal window embedded in an IDE) sends some kind of OS interrupt signal to the process running in the terminal. How can I find out what this signal is? I am looking for a way to capture the interrupt, run some clean up, and then abort. I am using Python and Windows.

0

2 Answers 2

3

You're looking for SIGHUP

SIGHUP The SIGHUP signal is sent to a process when its controlling terminal is closed. It was originally designed to notify the process of a serial line drop (a hangup). In modern systems, this signal usually means that the controlling pseudo or virtual terminal has been closed.[3] Many daemons will reload their configuration files and reopen their logfiles instead of exiting when receiving this signal.[4] nohup is a command to make a command ignore the signal.

2
  • This is true and helpful, but Python doesn't seem to have a good way of catching this signal in Windows. Thanks! Commented Apr 11, 2014 at 17:35
  • Stupidly I didn't relaise you were using Windows. See here - stackoverflow.com/questions/10156169/… - but it doesn't seem like you can do precisely what you want Commented Apr 12, 2014 at 18:16
0

Python does not seem to have an exception for this case. The closest would be SystemExit, however that does not actually capture the interrupt you're looking for.

Windows seems to actually send Ctrl+C before killing the process when you close a terminal, however capturing KeyboardInterrupt doesn't seem to work either. At this point you might want to look into the signal module.

Not the answer you're looking for? Browse other questions tagged or ask your own question.