[twisted-web] Deferred and threads

Hi all, I'm newbie and puzzled by some problems. I create five deferred instances, Then when all of them get the responses, will they run in five threads or one by one ? I'm not sure to use multiple threads if they'll usually run in synchrony. Best regards,
Joson

Hello Joson,
From my understanding deferreds are independent from each other. Their
"progress" along their callback chain is managed by the reactor and the way it handles and dispatches events.
There are several ways to link deferreds together if it is what you would like to achieve :
- you can use the deferred method chainDeferred that allows you to plug a deferred at the end of another deferred's callbacks chain; - you can use a DeferredList instance to keep track of a list of deferreds. It behaves as a Deferred, but you can configure it at instanciation to either fire its callback chain as soon as one of the deferreds in the list fires a callback, or to fire its callback chain only after all the deferreds in the list have fired theirs (default behavior).
If you want to know more, I advise you to check the documentation; the source code might also help. http://twistedmatrix.com/documents/10.0.0/api/twisted.internet.defer.Deferre...
I Hope this helps.
Regards
Matthieu
Le vendredi 19 mars 2010 à 18:36 +0800, Joson Mandaro a écrit :
Hi all, I'm newbie and puzzled by some problems.
I create five deferred instances, Then when all of them get
the responses, will they run in five threads or one by one ? I'm not sure to use multiple threads if they'll usually run in synchrony. Best regards,
Joson _______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

On Fri, Mar 19, 2010 at 7:05 AM, Matthieu HUIN matthieu.huin@wallix.com wrote:
Hello Joson,
From my understanding deferreds are independent from each other. Their
"progress" along their callback chain is managed by the reactor and the way it handles and dispatches events.
I don't think that's accurate. The reactor knows nothing about Deferreds. The logic for managing the callback chain is actually in Deferred itself.

On Fri, Mar 19, 2010 at 6:36 AM, Joson Mandaro joson.prog@gmail.com wrote:
Hi all, I'm newbie and puzzled by some problems. I create five deferred instances, Then when all of them get the responses, will they run in five threads or one by one ? I'm not sure to use multiple threads if they'll usually run in synchrony. Best regards,
I think this question is better for twisted-python mailing list. I'm not sure where you're confused but Deferreds and threads don't have anything to do with each other. Deferred callbacks don't execute in separate threads or anything like that. The order of callbacks depends on the order in which data arrives.
participants (3)
-
Drew Smathers
-
Joson Mandaro
-
Matthieu HUIN