[Twisted-Python] Need Exception that will stop ther reactor within twistd

Nicolas D. Cesar ncesar at lunix.com.ar
Mon Nov 27 13:19:00 EST 2006

El Sábado, 25 de Noviembre de 2006 02:39, glyph at divmod.com escribió:
> >I was wondering if twistd/the application class could have a "exit on
> >Exception" for this type of operations.
> In general this is a bad idea.  There are basically 3 kinds of code you can
> write with Twisted:
>   1. Infrastructure code, which implements a protocol and provides APIs for
> parsing and dealing with events.  This kind of code should never contain a
> reactor.stop at all.
> 3. Programs which do one operation, then stop themselves.  This kind of
> code should contain exactly 1 call to reactor.stop, in the final
> callback/errback of the Deferred representing the operation that it is run
> to perform.
> It sounds like you are writing code of type 3.

Actually is type 1, but there are horrible (network) conditions were de 
application should stop.

> If you *don't* structure your program this way, then you'll discover later
> that sometimes, you want to run your particular operation TWICE in the
> lifetime of the process instead of once, and you will have to deal with
> dozens of calls to reactor.stop littered around your application in lots of
> places.

Even it's not type 3, I get your point. And thats why I didn't want to write 
ANY reactor.stop() call, instead just raise exceptions- And have a unnified 
reactor.stop() inside somewhere in twistd. But it seems I need to think 
another solution. Right now as a workaround, reactor.stop() will be inside my 
exception's __init__ function ;-)

> Don't try to always stop the *process* when your program is 
> complete: stop the *program* by keeping a Deferred around which represents
> its complete run.  That way the *driver* for the program is responsible for
> stopping it, and when you want to aggregate multiple runs of it, you can
> easily use a tool like DeferredList, or do something different in the
> callbacks at the end.

I couldn't understand much of this last parragraph (my English reading could 
be part of the problem). I understand algorithms mucho more when are written 
in python instead of English,  Do you have a link to some code explaning 

Thanks Glyph again for your detailed mail,
Nicolás D. César <ncesar at lunix.com.ar>
Lunix S.R.L. -[ http://www.lunix.com.ar ]-
GnuPG Public Key: gpg --keyserver wwwkeys.pgp.net --recv-key 0x3606F3E6
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20061127/2cbdd164/attachment.pgp 

More information about the Twisted-Python mailing list