[Twisted-Python] One big smile ...

Moshe Zadka m at moshez.org
Mon Jul 14 21:22:07 MDT 2003


On 14 Jul 2003, Abe Fettig <abe at fettig.net> wrote:

> Hmm, I guess I don't quite understand this.  Why should it matter if a
> services is being started by the parent or not?  Is there a chance the
> parent could think the service was still running when it really wasn't?

Yes.
The parent *will* call .startService/.stopService when it is appropriate.
So either make those callable twice in a row [unlike your example,
where it had a subtle bug in that case] or, better, use something orthogonal
like .enable/.disable. The advantage of .enable/.disable is that they
can keep in the service an attribute of "enabling desired" so that if
you restart the server, the service will stay disabled. Just make sure
__init__ sets .enabled=1, and have .startService check .enabled before
doing anything, etc...

> If I do this, I get an error on shutdown, as it tries to create a
> snapshot of the running app:

To avoid creating snapshorts, use the --no_save argument to twistd.

>         cPickle.PicklingError: Can't pickle
> __builtin__.ServiceWebManager: it's not found as
> __builtin__.ServiceWebManager

A better way, after you're beyond simply examples, is to put the
classes in a module. Even if you don't use the snapshots, they are
sometimes useful for post-mortem debugging.
-- 
Moshe Zadka -- http://moshez.org/
Buffy: I don't like you hanging out with someone that... short.
Riley: Yeah, a lot of young people nowadays are experimenting with shortness.
Agile Programming Language -- http://www.python.org/




More information about the Twisted-Python mailing list