Justin Warren ha scritto:
Greetings twisted gurus!
I'm hoping someone with a better algorithmic brain than I could offer some advice on a good way to do something in a twisty/pythonic way.
The pseudocode for what I want to do is:
for item in generator_that_fetches_rows_from_database: ... do_stuff() ...
where generator_that_fetches_rows_from_database is an object that uses enterprise.adbapi (or anything else) to fetch rows from a database and return them to the for..in.. loop.
This can be done, but you need a "pure" asynchronous PostgreSQL client. Here is an implementation in Twisted: http://hg.mperillo.ath.cx/twisted/pglib Each row is processed using the IRowConsumer interface. To keep it simple, a callback function is called for each row received from the backend. Using Python 2.5 generators you can (probabily) achieve what you want.
[...]
Manlio Perillo