[Twisted-Python] Need some pointers for writing asynchronous code for Twisted app

Tristan Seligmann mithrandi-twisted-python at mithrandi.za.net
Fri Mar 9 17:16:33 MST 2007


* Brian Costlow <brian.costlow at gmail.com> [2007-03-09 18:34:17 -0500]:

> 
> def connectionLost(self):
>    myDict = {}
>    d.defer.Deferred()
>    d.addCallback(finish)
>    myIterObj = self.myElementTree.getIterator()
>    def processChunk():
>        try:
>            foo = myIterObj.next()
>            do stuff with foo to process element to dict entry
>        except StopIteration:
>            d.callback(None)
>        except:
>            error handling stuff
>        else
>            reactor.callLater(0, processChunk)
>    return d

This is very similar to what twisted.internet.task.coiterate() does. See
the following:

    http://jcalderone.livejournal.com/24285.html
    http://twistedmatrix.com/documents/current/api/twisted.internet.task.html

-- 
mithrandi, i Ainil en-Balandor, a faer Ambar
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: </pipermail/twisted-python/attachments/20070310/2954f0e9/attachment.sig>


More information about the Twisted-Python mailing list