B
    u9a_,                 @   s   d dl Z d dlmZ d dlmZmZ d dlmZ yd dlm	Z	 W n e
k
rX   dZ	Y nX dddd	d
dgZyd dlmZ W n$ ek
r   G dd deZY nX G dd deZG dd dZG dd	 d	eZG dd
 d
eZG dd dZe	dkreZ	dS )    N)deque)heappushheappop)	monotonic)SimpleQueueEmptyFullQueuePriorityQueue	LifoQueuer   )r   c               @   s   e Zd ZdS )r   N)__name__
__module____qualname__ r   r   /usr/lib/python3.7/queue.pyr      s   c               @   s   e Zd ZdS )r   N)r   r   r   r   r   r   r   r      s   c               @   s   e Zd Zd ddZdd Zdd Zdd	 Zd
d Zdd Zd!ddZ	d"ddZ
dd Zdd Zdd Zdd Zdd Zdd ZdS )#r	   r   c             C   sN   || _ | | t | _t| j| _t| j| _t| j| _d| _	d S )Nr   )
maxsize_init	threadingZLockmutexZ	Condition	not_emptynot_fullall_tasks_doneunfinished_tasks)selfr   r   r   r   __init__!   s    

zQueue.__init__c          	   C   sH   | j 8 | jd }|dkr4|dk r*td| j   || _W d Q R X d S )N   r   z!task_done() called too many times)r   r   
ValueErrorZ
notify_all)r   Z
unfinishedr   r   r   	task_done8   s    

zQueue.task_donec          	   C   s,   | j  x| jr| j   q
W W d Q R X d S )N)r   r   wait)r   r   r   r   joinN   s    	z
Queue.joinc          	   C   s   | j 
 |  S Q R X d S )N)r   _qsize)r   r   r   r   qsize[   s    zQueue.qsizec          	   C   s   | j  |   S Q R X d S )N)r   r    )r   r   r   r   empty`   s    zQueue.emptyc          	   C   s0   | j   d| j  k o |  kS   S Q R X d S )Nr   )r   r   r    )r   r   r   r   fulln   s    z
Queue.fullTNc          	   C   s   | j  | jdkr|s*|  | jkrtnz|d krRxp|  | jkrN| j   q4W nR|dk rdtdn@t | }x4|  | jkr|t  }|dkrt| j | qpW | | |  jd7  _| j	
  W d Q R X d S )Nr   z''timeout' must be a non-negative numberg        r   )r   r   r    r   r   r   time_putr   r   notify)r   itemblocktimeoutendtime	remainingr   r   r   puty   s&    




z	Queue.putc          	   C   s   | j  |s|  stnn|d kr<xd|  s8| j   q$W nL|dk rNtdn:t | }x.|  s|t  }|dkrxt| j | qZW |  }| j  |S Q R X d S )Nr   z''timeout' must be a non-negative numberg        )	r   r    r   r   r   r$   _getr   r&   )r   r(   r)   r*   r+   r'   r   r   r   get   s$    





z	Queue.getc             C   s   | j |ddS )NF)r(   )r,   )r   r'   r   r   r   
put_nowait   s    zQueue.put_nowaitc             C   s   | j ddS )NF)r(   )r.   )r   r   r   r   
get_nowait   s    zQueue.get_nowaitc             C   s   t  | _d S )N)r   queue)r   r   r   r   r   r      s    zQueue._initc             C   s
   t | jS )N)lenr1   )r   r   r   r   r       s    zQueue._qsizec             C   s   | j | d S )N)r1   append)r   r'   r   r   r   r%      s    z
Queue._putc             C   s
   | j  S )N)r1   popleft)r   r   r   r   r-      s    z
Queue._get)r   )TN)TN)r   r   r   r   r   r   r!   r"   r#   r,   r.   r/   r0   r   r    r%   r-   r   r   r   r   r	      s   

 
c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
r
   c             C   s
   g | _ d S )N)r1   )r   r   r   r   r   r      s    zPriorityQueue._initc             C   s
   t | jS )N)r2   r1   )r   r   r   r   r       s    zPriorityQueue._qsizec             C   s   t | j| d S )N)r   r1   )r   r'   r   r   r   r%      s    zPriorityQueue._putc             C   s
   t | jS )N)r   r1   )r   r   r   r   r-      s    zPriorityQueue._getN)r   r   r   r   r    r%   r-   r   r   r   r   r
      s   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
r   c             C   s
   g | _ d S )N)r1   )r   r   r   r   r   r      s    zLifoQueue._initc             C   s
   t | jS )N)r2   r1   )r   r   r   r   r       s    zLifoQueue._qsizec             C   s   | j | d S )N)r1   r3   )r   r'   r   r   r   r%      s    zLifoQueue._putc             C   s
   | j  S )N)r1   pop)r   r   r   r   r-      s    zLifoQueue._getN)r   r   r   r   r    r%   r-   r   r   r   r   r      s   c               @   sH   e Zd Zdd ZdddZdddZd	d
 Zdd Zdd Zdd Z	dS )_PySimpleQueuec             C   s   t  | _td| _d S )Nr   )r   _queuer   Z	Semaphore_count)r   r   r   r   r   	  s    z_PySimpleQueue.__init__TNc             C   s   | j | | j  d S )N)r7   r3   r8   release)r   r'   r(   r)   r   r   r   r,     s    z_PySimpleQueue.putc             C   s4   |d k	r|dk rt d| j||s*t| j S )Nr   z''timeout' must be a non-negative number)r   r8   acquirer   r7   r4   )r   r(   r)   r   r   r   r.     s
    z_PySimpleQueue.getc             C   s   | j |ddS )NF)r(   )r,   )r   r'   r   r   r   r/   '  s    z_PySimpleQueue.put_nowaitc             C   s   | j ddS )NF)r(   )r.   )r   r   r   r   r0   /  s    z_PySimpleQueue.get_nowaitc             C   s   t | jdkS )Nr   )r2   r7   )r   r   r   r   r"   7  s    z_PySimpleQueue.emptyc             C   s
   t | jS )N)r2   r7   )r   r   r   r   r!   ;  s    z_PySimpleQueue.qsize)TN)TN)
r   r   r   r   r,   r.   r/   r0   r"   r!   r   r   r   r   r6      s   

	
r6   )r   collectionsr   heapqr   r   r$   r   r7   r   ImportError__all__r   AttributeError	Exceptionr   r	   r
   r   r6   r   r   r   r   <module>   s(   
 BA