[Twisted-Python] handling CTRL-C

Itamar Shtull-Trauring itamar at itamarst.org
Thu Apr 30 09:04:44 EDT 2009

On Thu, 2009-04-30 at 14:44 +0200, Fabrizio Mancini wrote:
> Hi,
> i know twisted already manage CTRL-C keystroke, but i'd like to add
> some other action when CTRL-C is pressed.
> I've implemented a perspective broker server, which have a
> DeferredQueue and a lot of elements in it.
> I'd like to write to a file all those elements before the program
> shuts down.
> Is there a way to handle this kind of situation?

def cleanupFunction():
   for item in queue:
reactor.addSystemEventTrigger("before", "shutdown", cleanupFunction)

The function can return a Deferred in order to delay shutdown during

More information about the Twisted-Python mailing list