MySQL 'generator' not closing connections I have the following function which is leaving connections open but I can't figure out why.

The Cursor class creates a python-generator type function, allowing me to iterate over millions of rows.

connection=MySQLdb.connect("", "", "", "",
                           cursorclass = MySQLdb.cursors.SSCursor)
cursor=connection.cursor()
cursor.execute("select id, ...", (profile_id, ...))
try:
    for row in cursor.fetchall():
        yield row
except:
    pass
finally:
    connection.close()


Where am I going wrong?
See if you have enable "connection pooling".  If so, don't worry about the connections staying open.