[Twisted-Python] Advice sought on application evolution

Tristan Seligmann mithrandi at mithrandi.net
Sat Mar 22 09:54:44 EDT 2008

* Matthew Glubb <matt at madebykite.com> [2008-03-22 09:47:09 +0000]:

> Each successive call of x.bar must wait for the previous one to  
> complete. Whereas in the following example x.bar() is called in parallel 
> for each item in self.someList:
> def foo(self):
>     d = defer.Deferred()
>     self._done_count = 0
>     for x in self.somelist:
>         x.bar().addCallback(self._done_bar, d)
>     return d
> def _done_bar(self, result, d):
>     self._done_count = self._done_count + 1
>     if self._done_count == len(self.somelist):
>         d.callback(result)

Of course, you can also write this something like this (using
inlineCallbacks style just to save me some typing):

def foo(self):
    ds = []
    for x in self.somelist:
    for d in ds:
        yield d
    # Even better would probably be:
    # yield gatherResults(ds)

But yes, the danger of accidentally serializing operations that don't
need to be serialized, and not even realising it, is one of the problems
with this coding style.
mithrandi, i Ainil en-Balandor, a faer Ambar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20080322/5777f2b5/attachment.pgp 

More information about the Twisted-Python mailing list