[Twisted-Python] cleanup at reactor.stop

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? Best regards, Henning Hraban Ramm Südkurier Medienhaus / MediaPro Support/Admin/Development Dept.

Henning.Ramm@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". - Matt -- __ / \__ Matt Goodall, Pollenation Internet Ltd \__/ \ w: http://www.pollenation.net __/ \__/ e: matt@pollenation.net / \__/ \ t: +44 (0)113 2252500 \__/ \__/ / \ Any views expressed are my own and do not necessarily \__/ reflect the views of my employer.

On Mon, 04 Apr 2005 15:00:52 +0100, Matt Goodall <matt@pollenation.net> wrote:
Henning.Ramm@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: <http://twistedmatrix.com/documents/current/howto/application> 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. Jp

Adding something like: reactor.addSystemEventTrigger('before', 'shutdown', methodToRunBeforeShutdown) before running reactor.run() should do the work. Regards, Umit
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".
participants (4)
-
Henning.Ramm@mediapro-gmbh.de
-
Jp Calderone
-
Matt Goodall
-
Ümit Öztosun