Commit 1d9b57ff authored by Denis Bilenko's avatar Denis Bilenko

examples/psycopg2_pool.py: move closeall() up

That way generic pool methods are grouped together.
parent 2229f9e4
...@@ -50,6 +50,14 @@ class DatabaseConnectionPool(object): ...@@ -50,6 +50,14 @@ class DatabaseConnectionPool(object):
def put(self, item): def put(self, item):
self.pool.put(item) self.pool.put(item)
def closeall(self):
while not self.pool.empty():
conn = self.pool.get_nowait()
try:
conn.close()
except Exception:
pass
@contextlib.contextmanager @contextlib.contextmanager
def connection(self): def connection(self):
conn = self.get() conn = self.get()
...@@ -98,14 +106,6 @@ class DatabaseConnectionPool(object): ...@@ -98,14 +106,6 @@ class DatabaseConnectionPool(object):
return return
return conn return conn
def closeall(self):
while not self.pool.empty():
conn = self.pool.get_nowait()
try:
conn.close()
except Exception:
pass
def execute(self, *args, **kwargs): def execute(self, *args, **kwargs):
with self.cursor() as cursor: with self.cursor() as cursor:
cursor.execute(*args, **kwargs) cursor.execute(*args, **kwargs)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment