<html><body>On 27 Nov, 06:19 pm, ncesar@lunix.com.ar wrote:<br />>El Sábado, 25 de Noviembre de 2006 02:39, glyph@divmod.com escribió:<br />>> >I was wondering if twistd/the application class could have a "exit on<br />>> >Exception" for this type of operations.<br /><br />>> In general this is a bad idea.  There are basically 3 kinds of code you can<br />>> write with Twisted:<br />>><br />>>   1. Infrastructure code, which implements a protocol and provides APIs for<br />>> parsing and dealing with events.  This kind of code should never contain a<br />>> reactor.stop at all.<br /><br />>Actually is type 1, but there are horrible (network) conditions were de<br />>application should stop.<br /><br />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?<br /><br />>Even it's not type 3, I get your point. And thats why I didn't want to write<br />>ANY reactor.stop() call, instead just raise exceptions- And have a unnified<br />>reactor.stop() inside somewhere in twistd. But it seems I need to think<br />>another solution. Right now as a workaround, reactor.stop() will be inside my<br />>exception's __init__ function ;-)<br /><br />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. :)<br /><br />>> Don't try to always stop the *process* when your program is<br />>> complete: stop the *program* by keeping a Deferred around which represents<br />>> its complete run.  That way the *driver* for the program is responsible for<br />>> stopping it, and when you want to aggregate multiple runs of it, you can<br />>> easily use a tool like DeferredList, or do something different in the<br />>> callbacks at the end.<br />><br />>I couldn't understand much of this last parragraph (my English reading could<br />>be part of the problem). I understand algorithms mucho more when are written<br />>in python instead of English,  Do you have a link to some code explaning<br />>this?<br /><br />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.<br /></body></html>