twisted deferred/callbacks and asynchronous execution

Posted by NetSkay on Stack Overflow See other posts from Stack Overflow or by NetSkay
Published on 2010-12-27T21:07:40Z Indexed on 2010/12/27 22:53 UTC
Read the original article Hit count: 348

hey guys, quick question about twisted and python... im trying to figure out how can i make my code more asynchronous using twisted and ive come to sort of a dead end, if a function of mine returns a deferred object, then i add a list of callbacks, the first callback will be called after the deferred function provides some result through deferred_obj.callback, then, in the chain of callbacks, the first callback will do something with the data and call the second callback and etc. however chained callbacks will not be considered asynchronous because they're chained and the event loop will keep firing each one of them concurrently until there is no more, right? however, if i have a deferred object, and i attach as its callback the deferred_obj.callback as in d.addCallback(deferred_obj.callback) then this will be considered asynchronous, because the deferred_obj is waiting for the data, and then the method that will pass the data is waiting on data as well, however once i d.callback 'd' object processes the data then it call deferred_obj.callback however since this object is deferred, unlike the case of chained callbacks, it will execute asynchronously... correct?

meaning chained callbacks are NOT asynchronous while chained deferreds are, correct?

thank you

PS: assuming all of my code is non-blocking

© Stack Overflow or respective owner

Related posts about python

Related posts about asynchronous