[Twisted-Python] Need Exception that will stop ther reactor within twistd
glyph at divmod.com
glyph at divmod.com
Tue Nov 28 02:07:48 MST 2006
On 27 Nov, 06:19 pm, ncesar at lunix.com.ar wrote:
>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.
>Actually is type 1, but there are horrible (network) conditions were de
>application should stop.
No, there aren't. What happens when I run your application in-process with my webserver? Should the webserver stop simply because your protocol is not working?
>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 ;-)
Just don't call reactor.stop at all unless you are writing top-level infrastructure code. Your application should have some other, more structured way of reporting fatal shut-down errors to its run container (e.g. runContainer.applicationEncounteredFatal(xxx)), not simply raising exceptions and hoping someone is listening. Unless you give more specifics that indicate that your special case is special-er than any other I've seen before, I'll stand by this. :)
>> 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
>this?
It's hard for me to think of a program which does this in a simple way. If I can think of one I will post an example.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20061128/e1eb623b/attachment.html>
More information about the Twisted-Python
mailing list