On 12/16/2011 9:07 PM, Nick Coghlan wrote:
On Sat, Dec 17, 2011 at 11:00 AM, Alon Horevalon@horev.net wrote:
while I was implementing a connection pool i've noticed a pitfall of our beloved with statements:
with pool.get_connection() as conn: ....conn.execute(...) conn.execute(...) # the connection has been returned to the pool and does not belong to the user!
That's a bug in the connection pool implementation. If the underlying connection has been returned to the pool, the proxy returned by the context manager shouldn't work any more.
I believe Nick is saying that conn.__exit__ should close the connection and release the resource, that being the point of with statements and context managers. Can you open a tracker issue?
Try the above code structure with a file object and it will give you "IO operation on closed file".
Because file_object.__exit__ closes the connection to the OS resource.