Resources and non-exhausted generators

Emile van Sebille emile at fenx.com
Thu May 2 08:28:28 EDT 2002


Hamish Lawson
> I've written a generator (slightly modified below) that returns
results
> from a database. Normally this is intended to be run from a for-loop
> that will exhaust the produced results. However it occurred to me that
> if the generator is not run to completion, then the cursor and
> connection will not get properly closed. I can't see any way to do
this
> using a generator

Since you're doing a fetchall, couldn't you restructure to fetchall and
cursor.close before iterating?


--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list