[Twisted-Python] asynchronous python generator

Jean Daniel jeandaniel.browne at gmail.com
Mon Jul 12 17:46:14 EDT 2010

> You didn't have to switch to a while loop here.  The simplest fix for
> your for loop is this:
>    @inlineCallbacks
>    def gotConnection(conn):
>        for lineEvent in conn:
>            line = yield lineEvent
>            print line

Yes, I did that too. I wanted the loop to be able to terminate without
user intervention on a signalisation message: this is handy with for
when it is only a matter of raising StopIteration. In our two
examples, the user will have to be prepared for Exception to stop the

Thank you,

> But aside from that...
> No, you must have the `yield` somewhere in the function.  If you want
> something less scrutable than this, then you probably want something
> like corotwine.
> Jean-Paul
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

More information about the Twisted-Python mailing list