Fix issue with class instantiation

This commit is contained in:
Israel Brewster 2017-06-08 14:19:11 -08:00 committed by Changaco
parent 27baeab637
commit 75fad2d361

View File

@ -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