twisted: catch keyboardinterrupt and shutdown properly

Viewed 9006

UPDATE: For ease of reading, here is how to add a callback before the reactor gets shutdown:

reactor.addSystemEventTrigger('before', 'shutdown', callable)

Original question follows.


If I have a client connected to a server, and it's chilling in the reactor main loop waiting for events, when I hit CTRL-C, I get a "Connection to the other side was lost in a non-clean fashion: Connection lost." How can I set it up so that I know when a KeyboardInterrupt happens, so that I can do proper clean-up and disconnect cleanly? Or how can I implement a cleaner way to shutdown that doesn't involve CTRL-C, if possible?

2 Answers
Related