[Twisted-Python] Service dependencies
Hi, I have a couple of services. The second is dependent on the first being fully initialised before the second gets set up. I thought that the order of Service startup was typically handled by organising services in a hierarchy, and that the startup of the hierarchy understood deferreds. I was wrong - service.Application is a MultiService and only understands deferreds in stopService. There's a DependentMultiService class in twisted.internet.app but that entire module has been deprecated. Is there a reason why the MultiService does not support deferreds in startService? Is there a reason that DependentMultiService was not moved across to the twisted.application package? In other words, what is the recommended way of starting services in the correct order, including waiting for them to get initialised fully, these days? Thanks. - 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 1/19/06, Matt Goodall <matt@pollenation.net> wrote:
Hi,
In other words, what is the recommended way of starting services in the correct order, including waiting for them to get initialised fully, these days?
I'd say if service B relies on servcie A, then B.startService must explicitely call A.startService(). Of course, it requires that A.startService must be a noop if called more than once. Now for deferred, I'm not 100% sure, but I don't think there is something very wrong returning a deferred in startService. Eric.
On Thu, 19 Jan 2006 14:32:13 +0100, Eric Faurot <eric.faurot@gmail.com> wrote:
On 1/19/06, Matt Goodall <matt@pollenation.net> wrote:
Hi,
In other words, what is the recommended way of starting services in the correct order, including waiting for them to get initialised fully, these days?
I'd say if service B relies on servcie A, then B.startService must explicitely call A.startService().
Why?
Of course, it requires that A.startService must be a noop if called more than once.
Not a very common property of startService(). Few, if any, of the services Twisted provides offer this property.
Now for deferred, I'm not 100% sure, but I don't think there is something very wrong returning a deferred in startService.
Well, you won't get a spanking for it. Nothing pays any attention to the return value of startService, though. privilegedStartService is run before the reactor has started, so there's no way it could support Deferreds. startService could probably be modified to support Deferreds. MultiService is pretty lax about.... everything. I think this is just one of many possible improvements that could be made. Jean-Paul
On 1/19/06, Matt Goodall <matt@pollenation.net> wrote:
Hi,
I have a couple of services. The second is dependent on the first being fully initialised before the second gets set up.
<snip>
In other words, what is the recommended way of starting services in the
correct order, including waiting for them to get initialised fully, these days?
I actually wrote something like this today, a subclass of MultiService, because my main service was dependant on there being no other services running on the same machine, and I had to implement a PB client/server to ask the other instance to shut down. This is mostly because Windows sucks, and doesn't allow me to just do a "kill <pid>" on the old one, but gave me an excuse to start the PB integration of my app. I just subclassed MultiService and reimplemented startService and stopService appropriately, not chaining my sub-service starts until I was certain I had managed to start my own service, and not stopping my service until my sub-services had stopped. It's a fairly simple idiom, so it's probably pretty easy to implement yourself, but I'm surprised a generic one hasn't been written yet. Similarly I've had to write a new LoopingService that runs a "setup" callable before looping the main service, and also has a "minimum wait between calls" timer going on it. None of these have been particulalrly difficult.
Hi. I am coming back to resolve a service starting issue and wanted to bounce this around to see it this is feasible. First I want all services contained in a multiservice however my main service must be fully initialized before starting the other services. It is a pb client and I want to ensure I have a server connection first before the other services from the first once it starts. To do this I am thinking i can attempt start the main service first but run as a separate service (not a child of multiservice) If this main first service starts successfully, I will add it to a multiservice with the other services, then start the multiservice. First issue is that starting a service does not provide a deferred and I need to know I have made a connection to the pb server. Second is whether I can add a running service to a multiservice instance. Can someone advise on the feasibility of this approach. Many thanks. Regards, David
participants (5)
-
David Pratt
-
Eric Faurot
-
Jean-Paul Calderone
-
Matt Goodall
-
Moof