From c54083a88315a9caa9cdf748a5a324b5ffe085c3 Mon Sep 17 00:00:00 2001 From: diabolo-dan Date: Mon, 19 Sep 2016 21:29:00 +0100 Subject: [PATCH] lib/pool -- quick_cursor -- put connection back if there is an exception when connecting --- lib/pool.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/pool.py b/lib/pool.py index 2407fcc2..c8923106 100644 --- a/lib/pool.py +++ b/lib/pool.py @@ -126,10 +126,12 @@ class AbstractConnectionPool(object): @property @contextmanager def quick_cursor(self): - """A ContextManager for quickly getting a cursor""" - with self.getconn() as conn, conn.cursor() as cur: - yield cur - self.putconn(conn) + """A ContextManager for quickly getting a cursor""" + try: + with self.getconn() as conn, conn.cursor() as cur: + yield cur + finally: + self.putconn(conn) def _closeall(self): """Close all connections.