From 75fad2d361e541b4e4a008814c0fcf504ae4f4bd Mon Sep 17 00:00:00 2001 From: Israel Brewster Date: Thu, 8 Jun 2017 14:19:11 -0800 Subject: [PATCH] Fix issue with class instantiation --- lib/pool.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/pool.py b/lib/pool.py index b90267d9..6deeb807 100644 --- a/lib/pool.py +++ b/lib/pool.py @@ -189,24 +189,24 @@ class ThreadedConnectionPool(AbstractConnectionPool): class CachingConnectionPool(AbstractConnectionPool): """A connection pool that works with the threading module and caches connections""" - # A dictionary to hold connection ID's and when they should be removed from the pool - # Keys are id(connection) and vlaues are expiration time - # Storing the expiration time on the connection itself might be preferable, if possible. - from collections import OrderedDict - _expirations = OrderedDict() - def __init__(self, minconn, maxconn, lifetime = 3600, *args, **kwargs): """Initialize the threading lock.""" import threading - from datetime import datetime, timedelta AbstractConnectionPool.__init__( self, minconn, maxconn, *args, **kwargs) self._lock = threading.Lock() self._lifetime = lifetime + # A dictionary to hold connection ID's and when they should be removed from the pool + # Keys are id(connection) and vlaues are expiration time + # Storing the expiration time on the connection itself might be preferable, if possible. + from collections import OrderedDict + self._expirations = OrderedDict() + def _connect(self, key=None): """Create a new connection, assign it to 'key' if not None, And assign an expiration time""" + from datetime import datetime, timedelta conn = psycopg2.connect(*self._args, **self._kwargs) if key is not None: self._used[key] = conn