[Twisted-Python] cleanup at reactor.stop

Jp Calderone exarkun at divmod.com
Mon Apr 4 10:18:40 EDT 2005

On Mon, 04 Apr 2005 15:00:52 +0100, Matt Goodall <matt at pollenation.net> wrote:
>Henning.Ramm at mediapro-gmbh.de wrote:
> >This is probably a stupid question, but I'm stuck...
> >
> >I need to clean up some objects if (that is, before) reactor.stop is called.
> >Is there something like reactor.runAtShutdown() or how should I do this?
> >
> You can hook into the reactor by registering a system event callback. 
> See  twisted.internet.interfaces.IReactorCore's addSystemEventTrigger, 
> removeSystemEventTrigger and fireSystemEvent.
> You may need to grep the Twisted code to find out all the events that 
> are actually fired but the one you want is "shutdown".

  You can also use application services, which are implemented in terms of the system event trigger API.  A very incomplete look at services is present at:


  To create your own kind of service, simply subclass twisted.application.service.Service.  To get shutdown notification, override stopService.  It may return a Deferred to delay shutdown if necessary.


More information about the Twisted-Python mailing list