Twisted 100% event driven or hybrid?

exarkun at exarkun at
Wed Sep 23 16:44:13 CEST 2009

On 05:55 am, jacopo.pecci at wrote:
>I am diving into Twisted and Perspective Broker (PB) in particular. I
>am designing a system  having several models running on different
>machines, they need to be recalculated periodically, I have to collect
>the results, process them and start again from the beginning.
>It is not clear to me if I can blend some event driven programming
>with a more traditional one where the flow would be deterministic.
>In my case I have to iterate on a list of models and send the request
>of recalculation to the specific machine where the model resides. I
>don 19t want to wait for each single result but I want to sent all the
>requests in one go. In this phase I am happy to have an event driven
>framework with callbacks. Then I have to stop and wait for all the
>results to be ready, I collect and process them. From now on I don 19t
>need a the system to be event drive any more, the processing should
>occur only on the master machine, following a deterministic flow.
>As soon as finished I am ready to start again to resubmit the models
>for recalculation and so on. This should go on forever.
>Is  it possible to have an hybrid system like this? If I call
> at the certain point of the execution where does the
>execution continue from? Would this be a good design or in general is
>better to keep a 100% event drive system even if I don 19t actually need
>to handle asynchronicity for big chunks of the code.

If you're happy to block event processing, then there's no reason you 
can't do just that - once you have your results, start processing them 
in a blocking manner.  Twisted will not service events while you're 
doing this, but as long as you're happy with that, it doesn't really 
matter to Twisted.  You might not be as happy with this later on if your 
requirements change, but you can always worry about that later.

In particular, though, there's no reason or need to call reactor.stop() 
in order to "switch" to your non-event driven code.  Wherever you were 
thinking of putting that call, just put your non-event driven code there 


More information about the Python-list mailing list