On 02/11/11 10:40, Umit Oztosun wrote:

> I have lots of similar loops all over the place and a more generic
> solution would be great. I am also aware of deferToThread but I am
> trying to avoid using threads.

Well, deferToThread gives you all kinds of problems re: talking to the 
reactor from threads, so avoid.

You could try it as a cooperator

from twisted.internet import task

@defer.inlineCallbacks
def operation():
   result = yield somesql()
   # n.b. generator expression!
   work = (process(item) for item in result)
   yield task.coiterate(work)

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to