ó
O'—^c           @@  s|  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d d l m	 Z	 d d l
 m Z d d l m Z d d l m Z d d l m Z m Z m Z m Z d d	 l m Z m Z m Z m Z m Z d d
 l m Z m Z d d l m Z d d d g Z d e  f d „  ƒ  YZ! e  ƒ  Z" d e! f d „  ƒ  YZ# d e  f d „  ƒ  YZ$ d e$ f d „  ƒ  YZ% d S(   i    (   t   absolute_importNi   (   t   Pipe(   t	   _billiard(   t	   get_errno(   t	   monotonic(   t   Lockt   BoundedSemaphoret	   Semaphoret	   Condition(   t   debugt   errort   infot   Finalizet   register_after_fork(   t   Emptyt   Full(   t   assert_spawningt   Queuet   SimpleQueuet   JoinableQueuec           B@  sÑ   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z e d d „ Z	 e d d „ Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   s4   
    Queue type using a pipe, buffer and thread
    i    c         C@  sÉ   | d k r t  j j } n  | |  _ t d t ƒ \ |  _ |  _ t ƒ  |  _	 t
 j ƒ  |  _ t j d k ru d  |  _ n t ƒ  |  _ t | ƒ |  _ t |  _ |  j ƒ  t j d k rÅ t |  t j ƒ n  d  S(   Ni    t   duplext   win32(   R   t   SemLockt   SEM_VALUE_MAXt   _maxsizeR   t   Falset   _readert   _writerR   t   _rlockt   ost   getpidt   _opidt   syst   platformt   Nonet   _wlockR   t   _semt   _ignore_epipet   _after_forkR   R   (   t   selft   maxsize(    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt   __init__"   s    		
c         C@  s>   t  |  ƒ |  j |  j |  j |  j |  j |  j |  j |  j f S(   N(	   R   R%   R   R   R   R   R#   R$   R   (   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt   __getstate__6   s    
c      	   C@  sD   | \ |  _  |  _ |  _ |  _ |  _ |  _ |  _ |  _ |  j ƒ  d  S(   N(	   R%   R   R   R   R   R#   R$   R   R&   (   R'   t   state(    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt   __setstate__;   s    6c         C@  s   t  d ƒ t j t j ƒ  ƒ |  _ t j ƒ  |  _ d  |  _	 d  |  _
 t |  _ t |  _ d  |  _ |  j j |  _ |  j j |  _ |  j j |  _ d  S(   Ns   Queue._after_fork()(   R	   t	   threadingR   R   t	   _notemptyt   collectionst   dequet   _bufferR"   t   _threadt   _jointhreadR   t   _joincancelledt   _closedt   _closeR   t   sendt   _sendR   t   recvt   _recvt   pollt   _poll(   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR&   @   s    
					c         C@  s{   |  j  s t ‚ |  j j | | ƒ s. t ‚ n  |  j > |  j d  k rT |  j ƒ  n  |  j	 j
 | ƒ |  j j ƒ  Wd  QXd  S(   N(   R5   t   AssertionErrorR$   t   acquireR   R.   R2   R"   t   _start_threadR1   t   appendt   notify(   R'   t   objt   blockt   timeout(    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt   putM   s    	
c         C@  sü   | rB | d  k rB |  j " |  j ƒ  } |  j j ƒ  | SWd  QXn¶ | rX t ƒ  | } n  |  j j | | ƒ sv t ‚ n  zq | r´ | t ƒ  } | d k  s¨ |  j | ƒ rÉ t ‚ qÉ n |  j ƒ  sÉ t ‚ n  |  j ƒ  } |  j j ƒ  | SWd  |  j j ƒ  Xd  S(   Ni    (	   R"   R   R:   R$   t   releaseR   R>   R   R<   (   R'   RC   RD   t   rest   deadline(    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt   getX   s(    
		c         C@  s   |  j  |  j j j ƒ  S(   N(   R   R$   t   _semlockt
   _get_value(   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt   qsizeq   s    c         C@  s   |  j  ƒ  S(   N(   R<   (   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt   emptyv   s    c         C@  s   |  j  j j ƒ  S(   N(   R$   RJ   t   _is_zero(   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt   fully   s    c         C@  s   |  j  t ƒ S(   N(   RI   R   (   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt
   get_nowait|   s    c         C@  s   |  j  | t ƒ S(   N(   RE   R   (   R'   RB   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt
   put_nowait   s    c         C@  s0   t  |  _ |  j j ƒ  |  j r, |  j ƒ  n  d  S(   N(   t   TrueR5   R   t   closeR6   (   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyRS   ‚   s    		c         C@  s3   t  d ƒ |  j s t ‚ |  j r/ |  j ƒ  n  d  S(   Ns   Queue.join_thread()(   R	   R5   R=   R3   (   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt   join_threadˆ   s    
	c         C@  s<   t  d ƒ t |  _ y |  j j ƒ  Wn t k
 r7 n Xd  S(   Ns   Queue.cancel_join_thread()(   R	   RR   R4   R3   t   cancelt   AttributeError(   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt   cancel_join_threadŽ   s    
	c      
   C@  s  t  d ƒ |  j j ƒ  t j d t j d |  j |  j |  j |  j	 |  j
 j |  j f d d ƒ |  _ t |  j _ t  d ƒ |  j j ƒ  t  d ƒ |  j t j ƒ  k } |  j rè | rè t |  j t j t j |  j ƒ g d d	 ƒ|  _ n  t |  t j |  j |  j g d d
 ƒ|  _ d  S(   Ns   Queue._start_thread()t   targett   argst   namet   QueueFeederThreads   doing self._thread.start()s   ... done self._thread.start()t   exitpriorityiûÿÿÿi
   (   R	   R1   t   clearR-   t   ThreadR   t   _feedR.   R8   R#   R   RS   R%   R2   RR   t   daemont   startR   R   R   R4   R   t   _finalize_joint   weakreft   refR3   t   _finalize_closeR6   (   R'   t   created_by_this_process(    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR?   –   s*    
		

	c         C@  sD   t  d ƒ |  ƒ  } | d  k	 r6 | j ƒ  t  d ƒ n
 t  d ƒ d  S(   Ns   joining queue threads   ... queue thread joineds   ... queue thread already dead(   R	   R"   t   join(   t   twrt   thread(    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyRb   ¼   s    
	
c         C@  s2   t  d ƒ |  |  j t ƒ | j ƒ  Wd  QXd  S(   Ns   telling queue thread to quit(   R	   R@   t	   _sentinelRA   (   t   buffert   notempty(    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyRe   Æ   s    
c         C@  s•  t  d ƒ d d l m } | } | j } |  j }	 t }
 t j d k rP | } n d  } y¡ xš |  |  ss | ƒ  n  Wd  QXye x^ |	 ƒ  } | |
 k r© t  d ƒ | ƒ  d  S| d  k rÂ | | ƒ q |  | | ƒ Wd  QXq WWq\ t	 k
 rñ q\ Xq\ WWn— t
 k
 r} | r(t | ƒ t j k r(d  SyQ | ƒ  rJt d | d t ƒn. t d | d t ƒsxd d  l } | j ƒ  n  Wq‘t
 k
 rŒq‘Xn Xd  S(	   Ns$   starting thread to feed data to pipei   (   t
   is_exitingR   s%   feeder thread got sentinel -- exitings   error in queue thread: %rt   exc_infoi    (   R	   t   utilRm   t   waitt   popleftRj   R    R!   R"   t
   IndexErrort	   ExceptionR   t   errnot   EPIPER   RR   R
   t	   tracebackt	   print_exc(   Rk   Rl   R7   t	   writelockRS   t   ignore_epipeRm   t   ncondt   nwaitt   bpopleftt   sentinelt   wlockRB   t   excRv   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR_   Í   sN    
				
		N(   t   __name__t
   __module__t   __doc__R)   R*   R,   R&   RR   R"   RE   RI   RL   RM   RO   RP   RQ   RS   RT   RW   R?   t   staticmethodRb   Re   R_   (    (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR      s&   												&
c           B@  sM   e  Z d  Z d d „ Z d „  Z d „  Z e d d „ Z d „  Z	 d „  Z
 RS(	   sé   
    A queue type which also supports join() and task_done() methods

    Note that if you do not call task_done() for each finished task then
    eventually the counter's semaphore may overflow causing Bad Things
    to happen.
    i    c         C@  s/   t  j |  | ƒ t d ƒ |  _ t ƒ  |  _ d  S(   Ni    (   R   R)   R   t   _unfinished_tasksR   t   _cond(   R'   R(   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR)     s    c         C@  s   t  j |  ƒ |  j |  j f S(   N(   R   R*   R…   R„   (   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR*     s    c         C@  s.   t  j |  | d  ƒ | d \ |  _ |  _ d  S(   Niþÿÿÿ(   R   R,   R…   R„   (   R'   R+   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR,     s    c      
   C@  s˜   |  j  s t ‚ |  j j | | ƒ s. t ‚ n  |  j [ |  j K |  j d  k r^ |  j	 ƒ  n  |  j
 j | ƒ |  j j ƒ  |  j j ƒ  Wd  QXWd  QXd  S(   N(   R5   R=   R$   R>   R   R.   R…   R2   R"   R?   R1   R@   R„   RF   RA   (   R'   RB   RC   RD   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyRE     s    	

c         C@  sW   |  j  H |  j j t ƒ s+ t d ƒ ‚ n  |  j j j ƒ  rM |  j  j ƒ  n  Wd  QXd  S(   Ns!   task_done() called too many times(   R…   R„   R>   R   t
   ValueErrorRJ   RN   t
   notify_all(   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt	   task_done&  s
    
c         C@  s6   |  j  ' |  j j j ƒ  s, |  j  j ƒ  n  Wd  QXd  S(   N(   R…   R„   RJ   RN   Rp   (   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyRg   -  s    
N(   R€   R   R‚   R)   R*   R,   RR   R"   RE   Rˆ   Rg   (    (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR     s   			t   _SimpleQueuec           B@  sA   e  Z d  Z e e d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s<   
    Simplified Queue type -- really just a locked pipe
    c         C@  sT   t  d t d | d | ƒ \ |  _ |  _ |  j j |  _ d  |  _ |  _ |  j	 ƒ  d  S(   NR   t	   rnonblockt	   wnonblock(
   R   R   R   R   R;   R<   R"   R   R#   t   _make_methods(   R'   RŠ   R‹   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR)   8  s
    !c         C@  s   |  j  ƒ  S(   N(   R<   (   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyRM   @  s    c         C@  s&   t  |  ƒ |  j |  j |  j |  j f S(   N(   R   R   R   R   R#   (   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR*   C  s    
c         C@  s,   | \ |  _  |  _ |  _ |  _ |  j ƒ  d  S(   N(   R   R   R   R#   RŒ   (   R'   R+   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR,   G  s    c         @  sñ   |  j  j ‰  y |  j  j ‰ Wn t k
 r; |  j  j ‰ n X|  j ‰ ˆ d  k	 rŠ ‡  ‡ f d †  } | |  _ ‡ ‡ f d †  } | |  _ n ˆ  |  _ ˆ |  _ |  j	 d  k r½ |  j
 j |  _ n0 |  j
 j ‰ |  j	 ‰ ‡ ‡ f d †  } | |  _ d  S(   Nc           @  s   ˆ  ˆ  ƒ  SWd  QXd  S(   N(    (    (   R9   t   rlock(    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyRI   T  s    c           @  s   ˆ  ˆ  ƒ  SWd  QXd  S(   N(    (    (   t   recv_payloadR   (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt   get_payloadY  s    c         @  s   ˆ  ˆ  |  ƒ SWd  QXd  S(   N(    (   RB   (   R7   R~   (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyRE   h  s    (   R   R9   RŽ   RV   t
   recv_bytesR   R"   RI   R   R#   R   R7   RE   (   R'   RI   R   RE   (    (   R9   RŽ   R   R7   R~   s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyRŒ   K  s&    					(	   R€   R   R‚   R   R)   RM   R*   R,   RŒ   (    (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR‰   3  s   			c           B@  s   e  Z d  „  Z RS(   c         C@  sV   t  d t ƒ \ |  _ |  _ t ƒ  |  _ t j d k r? t ƒ  n d  |  _	 |  j
 ƒ  d  S(   NR   R   (   R   R   R   R   R   R   R    R!   R"   R#   RŒ   (   R'   (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR)   p  s    !(   R€   R   R)   (    (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyR   n  s   (&   t
   __future__R    R    R   R-   R/   Rc   Rt   t    R   t   _extR   t   compatR   t   fiveR   t   synchronizeR   R   R   R   Ro   R	   R
   R   R   R   R   R   t   forkingR   t   __all__t   objectR   Rj   R   R‰   R   (    (    (    s1   /tmp/pip-unpacked-wheel-40MfcW/billiard/queues.pyt   <module>	   s(   "(ã	/;