[Twisted-Python] Question about deferreds
dfarrell at mypublisher.com
Tue May 5 09:48:25 EDT 2009
I consider myself a Twisted "newbie", so this might seem like a simple
couple of questions, hope you'll indulge me.
When I first began experimenting with deferreds I was breaking up tasks
into sequences of steps something like this:
d = Deferred()
When this runs I was under the mistaken impression that at the end of
each callback (step1, step2, step3, etc) the deferred would yield back
to the main loop (reactor) and allow other deferreds to run. Now I know
that the callback functions run sequentially one after another with no
break. So my first question is this: what is the advantage of this over
just combining the callback functions into one big function?, something
d = Deferred()
If step1(), step2() and step3() take a fair bit of time to complete,
doesn't this effectively block the reactor loop for the entire exection
of all the steps?
My second question is related to this; what is a recommended way to
create the cooperative state machine I'm thinking of using deferreds?
For example if I create something like this:
d1 = Deferred()
d2 = Deferred()
How do I get the execution of this to be this:
I want to have the state machines I create cooperatively 'multi-task',
yielding control back to the main loop at each state transition.
Thanks in advance for any help, guidance or references you can provide.
I really enjoy Twisted, I'm still working on getting the 'Zen' of it.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python