B
    H/\                 @   sx   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddgZ	e
edd	d
g\ZZZG dd deZG dd deZdS )a  A clone of threading module (version 2.7.2) that always
targets real OS threads. (Unlike 'threading' which flips between
green and OS threads based on whether the monkey patching is in effect
or not).

This module is missing 'Thread' class, but includes 'Queue'.
    )absolute_import)deque)monkey)thread_mod_nameLockQueuestart_new_threadallocate_lock	get_identc               @   sT   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )
_Conditionc             C   sv   || _ g | _y|j| _W n tk
r,   Y nX y|j| _W n tk
rN   Y nX y|j| _W n tk
rp   Y nX d S )N)_Condition__lock_Condition__waiters_release_saveAttributeError_acquire_restore	_is_owned)selflock r   0lib/python3.7/site-packages/gevent/_threading.py__init__"   s    z_Condition.__init__c             C   s
   | j  S )N)r   	__enter__)r   r   r   r   r   6   s    z_Condition.__enter__c             C   s   | j |||S )N)r   __exit__)r   tvtbr   r   r   r   9   s    z_Condition.__exit__c             C   s   d| j t| jf S )Nz<Condition(%s, %d)>)r   lenr   )r   r   r   r   __repr__<   s    z_Condition.__repr__c             C   s   | j   d S )N)r   release)r   r   r   r   r   ?   s    z_Condition._release_savec             C   s   | j   d S )N)r   acquire)r   xr   r   r   r   B   s    z_Condition._acquire_restorec             C   s   | j dr| j   dS dS )Nr   FT)r   r   r   )r   r   r   r   r   E   s    
z_Condition._is_ownedc          	   C   s@   t  }|  | j| |  }z|  W d | | X d S )N)r   r   r   appendr   r   )r   waiterZsaved_stater   r   r   waitM   s    z_Condition.waitc             C   s0   y| j  }W n tk
r"   Y n
X |  d S )N)r   pop
IndexErrorr   )r   r"   r   r   r   
notify_oneX   s
    z_Condition.notify_oneN)__name__
__module____qualname__r   r   r   r   r   r   r   r#   r&   r   r   r   r   r      s   r   c               @   sP   e Zd ZdZdZdd Zdd ZefddZd	d
 Z	dd Z
dd Zdd ZdS )r   zCCreate a queue object.

    The queue is always infinite size.
    )_queue_mutex
_not_emptyunfinished_tasksc             C   s&   t  | _t | _t| j| _d| _d S )Nr   )r   r*   r   r+   r   r,   r-   )r   r   r   r   r   k   s    zQueue.__init__c          	   C   s>   | j . | jd }|dkr*|dk r*td|| _W dQ R X dS )a.  Indicate that a formerly enqueued task is complete.

        Used by Queue consumer threads.  For each get() used to fetch a task,
        a subsequent call to task_done() tells the queue that the processing
        on the task is complete.

        If a join() is currently blocking, it will resume when all items
        have been processed (meaning that a task_done() call was received
        for every item that had been put() into the queue).

        Raises a ValueError if called more times than there were items
        placed in the queue.
           r   z!task_done() called too many timesN)r+   r-   
ValueError)r   Z
unfinishedr   r   r   	task_donex   s    
zQueue.task_donec             C   s
   || j S )z9Return the approximate size of the queue (not reliable!).)r*   )r   r   r   r   r   qsize   s    zQueue.qsizec             C   s
   |    S )zCReturn True if the queue is empty, False otherwise (not reliable!).)r1   )r   r   r   r   empty   s    zQueue.emptyc             C   s   dS )zBReturn True if the queue is full, False otherwise (not reliable!).Fr   )r   r   r   r   full   s    z
Queue.fullc          	   C   s:   | j * | j| |  jd7  _| j   W dQ R X dS )z$Put an item into the queue.
        r.   N)r,   r*   r!   r-   r&   )r   itemr   r   r   put   s    z	Queue.putc          	   C   s6   | j & x| js| j   q
W | j }|S Q R X dS )z2Remove and return an item from the queue.
        N)r,   r*   r#   popleft)r   r4   r   r   r   get   s
    
z	Queue.getN)r'   r(   r)   __doc__	__slots__r   r0   r   r1   r2   r3   r5   r7   r   r   r   r   r   c   s   N)r8   Z
__future__r   collectionsr   Zgeventr   Zgevent._compatr   __all__Zget_originalr   r   Zget_thread_identobjectr   r   r   r   r   r   <module>   s   D