mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 17:06:33 +03:00
Update methods of ThreadedConnectionPool
Updated methods of the ThreadedConnectionPool class to use the elegant context manager syntax.
This commit is contained in:
parent
e9a62bf418
commit
766f06f290
15
lib/pool.py
15
lib/pool.py
|
@ -181,24 +181,15 @@ class ThreadedConnectionPool(AbstractConnectionPool):
|
|||
|
||||
def getconn(self, key=None):
|
||||
"""Get a free connection and assign it to 'key' if not None."""
|
||||
self._lock.acquire()
|
||||
try:
|
||||
with self._lock:
|
||||
return self._getconn(key)
|
||||
finally:
|
||||
self._lock.release()
|
||||
|
||||
def putconn(self, conn=None, key=None, close=False):
|
||||
"""Put away an unused connection."""
|
||||
self._lock.acquire()
|
||||
try:
|
||||
with self._lock:
|
||||
self._putconn(conn, key, close)
|
||||
finally:
|
||||
self._lock.release()
|
||||
|
||||
def closeall(self):
|
||||
"""Close all connections (even the one currently in use.)"""
|
||||
self._lock.acquire()
|
||||
try:
|
||||
with self._lock:
|
||||
self._closeall()
|
||||
finally:
|
||||
self._lock.release()
|
||||
|
|
Loading…
Reference in New Issue
Block a user