[Twisted-Python] subclassing and class methods returning deferreds
Hi, I wanted to have a class hierarchy where .stop methods would make sure everything is cleaned up properly before reactors get stopped and such. The obvious way to do that was to return a deferred that gets fired when everything else is done, and make sure that deferred is handled correctly everywhere. So I wrote up an example that does this: http://thomas.apestaart.org/download/tmp/subclass-deferred.py I'd appreciate it if someone who's interested would take a look at it to suggest some improvements, as I'm sure I might have overthought things a little, or maybe there are better ways to do something like this. Thanks, Thomas Dave/Dina : future TV today ! - http://www.davedina.org/ <-*- thomas (dot) apestaart (dot) org -*-> Welcome to Hits City, Jeff K - Population: you <-*- thomas (at) apestaart (dot) org -*-> URGent, best radio on the net - 24/7 ! - http://urgent.fm/
On Thu, 2005-07-21 at 12:51 +0200, Thomas Vander Stichele wrote:
Hi,
I wanted to have a class hierarchy where .stop methods would make sure everything is cleaned up properly before reactors get stopped and such.
That's what services (twisted.application.service) are for. The stopService method of a service can return a Deferred. Since they're a tree, all you need to do is hook up the root service to the reactor (which is what twistd does for you) and all child services will get shutdown as well.
On Thu, 2005-07-21 at 11:15 -0400, Itamar Shtull-Trauring wrote:
On Thu, 2005-07-21 at 12:51 +0200, Thomas Vander Stichele wrote:
Hi,
I wanted to have a class hierarchy where .stop methods would make sure everything is cleaned up properly before reactors get stopped and such.
That's what services (twisted.application.service) are for. The stopService method of a service can return a Deferred. Since they're a tree, all you need to do is hook up the root service to the reactor (which is what twistd does for you) and all child services will get shutdown as well.
I'm looking into hooking up the whole application part into the service framework, but stopService will then still need to tell these objects that are performing tasks to stop and wait for that, so it will still need to go up the hierarchy and process correctly. Or am I missing something ? Btw, I only found a short introduction on services and .tac files, but it doesn't really say what services are trying to solve, and when you should use them. Is there somewhere else I should look for that ? Thanks Thomas Dave/Dina : future TV today ! - http://www.davedina.org/ <-*- thomas (dot) apestaart (dot) org -*-> Gotta keep moving on lover you hide from me every time <-*- thomas (at) apestaart (dot) org -*-> URGent, best radio on the net - 24/7 ! - http://urgent.fm/
participants (2)
-
Itamar Shtull-Trauring -
Thomas Vander Stichele