mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-11-04 09:47:30 +03:00 
			
		
		
		
	Merge pull request #823 from jdufresne/dep-pool
Dropped deprecated PersistentConnectionPool
This commit is contained in:
		
						commit
						25fc044d13
					
				
							
								
								
									
										2
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								NEWS
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -31,6 +31,8 @@ Other changes:
 | 
			
		|||
- Dropped support for Python 2.6, 3.2, 3.3.
 | 
			
		||||
- Dropped `psycopg1` module.
 | 
			
		||||
- Dropped deprecated `!register_tstz_w_secs()` (was previously a no-op).
 | 
			
		||||
- Dropped deprecated `!PersistentConnectionPool`. This pool class was mostly
 | 
			
		||||
  designed to interact with Zope. Use `!ZPsycopgDA.pool` instead.
 | 
			
		||||
- No longer use 2to3 during installation for Python 2 & 3 compatability. All
 | 
			
		||||
  source files are now compatible with Python 2 & 3 as is.
 | 
			
		||||
- The `!psycopg2.test` package is no longer installed by ``python setup.py
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -58,11 +58,3 @@ be used.
 | 
			
		|||
.. autoclass:: ThreadedConnectionPool
 | 
			
		||||
 | 
			
		||||
    .. note:: This pool class can be safely used in multi-threaded applications.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
.. autoclass:: PersistentConnectionPool
 | 
			
		||||
 | 
			
		||||
    .. note::
 | 
			
		||||
 | 
			
		||||
        This pool class is mostly designed to interact with Zope and probably
 | 
			
		||||
        not useful in generic applications.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										55
									
								
								lib/pool.py
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								lib/pool.py
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -184,58 +184,3 @@ class ThreadedConnectionPool(AbstractConnectionPool):
 | 
			
		|||
            self._closeall()
 | 
			
		||||
        finally:
 | 
			
		||||
            self._lock.release()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PersistentConnectionPool(AbstractConnectionPool):
 | 
			
		||||
    """A pool that assigns persistent connections to different threads.
 | 
			
		||||
 | 
			
		||||
    Note that this connection pool generates by itself the required keys
 | 
			
		||||
    using the current thread id.  This means that until a thread puts away
 | 
			
		||||
    a connection it will always get the same connection object by successive
 | 
			
		||||
    `!getconn()` calls. This also means that a thread can't use more than one
 | 
			
		||||
    single connection from the pool.
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    def __init__(self, minconn, maxconn, *args, **kwargs):
 | 
			
		||||
        """Initialize the threading lock."""
 | 
			
		||||
        import warnings
 | 
			
		||||
        warnings.warn("deprecated: use ZPsycopgDA.pool implementation",
 | 
			
		||||
            DeprecationWarning)
 | 
			
		||||
 | 
			
		||||
        import threading
 | 
			
		||||
        AbstractConnectionPool.__init__(
 | 
			
		||||
            self, minconn, maxconn, *args, **kwargs)
 | 
			
		||||
        self._lock = threading.Lock()
 | 
			
		||||
 | 
			
		||||
        # we we'll need the thread module, to determine thread ids, so we
 | 
			
		||||
        # import it here and copy it in an instance variable
 | 
			
		||||
        import thread
 | 
			
		||||
        self.__thread = thread
 | 
			
		||||
 | 
			
		||||
    def getconn(self):
 | 
			
		||||
        """Generate thread id and return a connection."""
 | 
			
		||||
        key = self.__thread.get_ident()
 | 
			
		||||
        self._lock.acquire()
 | 
			
		||||
        try:
 | 
			
		||||
            return self._getconn(key)
 | 
			
		||||
        finally:
 | 
			
		||||
            self._lock.release()
 | 
			
		||||
 | 
			
		||||
    def putconn(self, conn=None, close=False):
 | 
			
		||||
        """Put away an unused connection."""
 | 
			
		||||
        key = self.__thread.get_ident()
 | 
			
		||||
        self._lock.acquire()
 | 
			
		||||
        try:
 | 
			
		||||
            if not conn:
 | 
			
		||||
                conn = self._used[key]
 | 
			
		||||
            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:
 | 
			
		||||
            self._closeall()
 | 
			
		||||
        finally:
 | 
			
		||||
            self._lock.release()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user