UPDATE: For ease of reading, here is how to add a callback before the reactor gets shutdown:
reactor.addSystemEventTrigger(\'before\', \'shutdown\', callable)
>
I'm not sure whether you talking about a client or a server that you've written.
Anyway, nothing wrong with 'CTRL-C'.
If you're writing a server as an Application. Subclass from twisted.application.service.Service
and define startService
and stopService
. Maintain a list of active protocol instances. Use stopService
to go through them and close them gracefully.
If you've got a client, you could also subclass Service
, but it could be simpler to use reactor.addSystemEventTrigger('before','shutdown',myCleanUpFunction)
, and close connection(s) gracefully in this function.