File: //opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/util/__pycache__/queue.cpython-37.pyc
B
��4]� � @ sd d Z ddlmZ ddlmZ ddlmZ dddgZG d d� de�Z G d
d� de�Z
G dd� d�ZdS )
a� An adaptation of Py2.3/2.4's Queue module which supports reentrant
behavior, using RLock instead of Lock for its mutex object. The
Queue object is used exclusively by the sqlalchemy.pool.QueuePool
class.
This is to support the connection pool's usage of weakref callbacks to return
connections to the underlying Queue, which can in extremely
rare cases be invoked within the ``get()`` method of the Queue itself,
producing a ``put()`` inside the ``get()`` and therefore a reentrant
condition.
� )�deque)�time� )� threading�Empty�Full�Queuec @ s e Zd ZdZdS )r z4Exception raised by Queue.get(block=0)/get_nowait().N)�__name__�
__module__�__qualname__�__doc__� r
r
�H/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/util/queue.pyr s c @ s e Zd ZdZdS )r z4Exception raised by Queue.put(block=0)/put_nowait().N)r r
r r r
r
r
r r $ s c @ s� e Zd Zd!dd�Zdd� Zdd� Zd d
� Zd"d
d�Zdd� Zd#dd�Z dd� Z
dd� Zdd� Zdd� Z
dd� Zdd� Zdd � ZdS )$r r Fc C s: | � |� t�� | _t�| j�| _t�| j�| _|| _dS )z�Initialize a queue object with a given maximum size.
If `maxsize` is <= 0, the queue size is infinite.
If `use_lifo` is True, this Queue acts like a Stack (LIFO).
N)�_initr �RLock�mutexZ Condition� not_empty�not_full�use_lifo)�self�maxsizer r
r
r �__init__+ s
zQueue.__init__c C s | j �� | �� }| j �� |S )z9Return the approximate size of the queue (not reliable!).)r �acquire�_qsize�release)r �nr
r
r �qsizeB s
zQueue.qsizec C s | j �� | �� }| j �� |S )zKReturn True if the queue is empty, False otherwise (not
reliable!).)r r �_emptyr )r r r
r
r �emptyJ s
zQueue.emptyc C s | j �� | �� }| j �� |S )zJReturn True if the queue is full, False otherwise (not
reliable!).)r r �_fullr )r r r
r
r �fullS s
z
Queue.fullTNc C s� | j �� z�|s| �� r�t�nl|dkr@xb| �� r<| j �� q(W nJ|dk rPtd��t� | }x.| �� r�|t� }|dkrzt�| j �|� q\W | �|� | j� � W d| j �
� X dS )a Put an item into the queue.
If optional args `block` is True and `timeout` is None (the
default), block if necessary until a free slot is
available. If `timeout` is a positive number, it blocks at
most `timeout` seconds and raises the ``Full`` exception if no
free slot was available within that time. Otherwise (`block`
is false), put an item on the queue if a free slot is
immediately available, else raise the ``Full`` exception
(`timeout` is ignored in that case).
Nr z#'timeout' must be a positive numberg )r r r r �wait�
ValueError�_time�_putr �notifyr )r �item�block�timeout�endtime� remainingr
r
r �put\ s&