ó
O'—^c           @@  s9  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 m Z m	 Z	 d d l
 m Z m Z d d l m Z d d l m Z m Z m Z d d l m Z m Z d d	 l m Z m Z d
 d d d d d g Z e	 ƒ  e e d ƒ ƒ \ Z Z e j j Z y e j j Z Wn? e  k
 rdy d  d l! m Z Wqee" k
 r`d Z qeXn Xd „  Z$ d e% f d „  ƒ  YZ d e f d „  ƒ  YZ& d e& f d „  ƒ  YZ' d
 e f d „  ƒ  YZ( d e f d „  ƒ  YZ) d e% f d „  ƒ  YZ* d e% f d „  ƒ  YZ+ e j, d k r5d „  Z- d „  Z. d „  Z/ n  d S(   i    (   t   absolute_importNi   (   t	   _billiardt   ensure_SemLock(   t   ranget	   monotonic(   t   current_process(   t   Finalizet   register_after_forkt   debug(   t   assert_spawningt   Popen(   t   bytest
   closeranget   Lockt   RLockt	   Semaphoret   BoundedSemaphoret	   Conditiont   Eventi   (   t
   sem_unlinkc         C@  s#   y |  j  SWn t k
 r n Xd  S(   N(   t   namet   AttributeError(   t   sl(    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt   _semname7   s    t   SemLockc           B@  sY   e  Z e j ƒ  Z d  „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e d „  ƒ Z RS(   c         C@  s  d d l  m } | p" t j d k } t rV t j | | | |  j ƒ  | ƒ } |  _ n t j | | | ƒ } |  _ t	 d | j
 ƒ |  j ƒ  t rt j d k rº d „  } t |  | ƒ n  t |  j ƒ d  k	 rt |  t |  j j f d d ƒt |  j j ƒ qn  d  S(   Ni   (   t   _forking_is_enabledt   win32s   created semlock with handle %sc         S@  s   |  j  j ƒ  d  S(   N(   t   _semlockt   _after_fork(   t   obj(    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR   P   s    t   exitpriorityi    (   t   forkingR   t   syst   platformR   R   R   t
   _make_nameR   R   t   handlet   _make_methodsR   R   t   NoneR   R   t   _cleanup_semaphore_if_leaked(   t   selft   kindt   valuet   maxvalueR   t   unlink_immediatelyR   R   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt   __init__A   s     %
	c         C@  s"   |  j  j |  _ |  j  j |  _ d  S(   N(   R   t   acquiret   release(   R'   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR$   ]   s    c         C@  s   |  j  j ƒ  S(   N(   R   t	   __enter__(   R'   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR/   a   s    c         G@  s   |  j  j | Œ  S(   N(   R   t   __exit__(   R'   t   args(    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR0   d   s    c         C@  s`   t  |  ƒ |  j } t j | j ƒ | j | j f } y | | j f 7} Wn t k
 r[ n X| S(   N(	   R	   R   R
   t   duplicate_for_childR#   R(   R*   R   R   (   R'   R   t   state(    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt   __getstate__g   s    
	!c         C@  s4   t  j j | Œ  |  _ t d | d ƒ |  j ƒ  d  S(   Ns    recreated blocker with handle %ri    (   R   R   t   _rebuildR   R   R$   (   R'   R3   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt   __setstate__q   s    c           C@  s&   d t  ƒ  j t j ƒ  t t j ƒ f S(   Ns	   /%s-%s-%s(   R   t
   _semprefixt   ost   getpidt   nextR   t   _counter(    (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR"   v   s    (   t   __name__t
   __module__t	   itertoolst   countR;   R,   R$   R/   R0   R4   R6   t   staticmethodR"   (    (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR   >   s   					
	c           B@  s&   e  Z d  d „ Z d „  Z d „  Z RS(   i   c         C@  s   t  j |  t | t ƒ d  S(   N(   R   R,   t	   SEMAPHOREt   SEM_VALUE_MAX(   R'   R)   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR,   ~   s    c         C@  s   |  j  j ƒ  S(   N(   R   t
   _get_value(   R'   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt	   get_value   s    c         C@  s5   y |  j  j ƒ  } Wn t k
 r, d } n Xd | S(   Nt   unknowns   <Semaphore(value=%s)>(   R   RC   t	   Exception(   R'   R)   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt   __repr__„   s
    
(   R<   R=   R,   RD   RG   (    (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR   |   s   	c           B@  s   e  Z d  d „ Z d „  Z RS(   i   c         C@  s   t  j |  t | | ƒ d  S(   N(   R   R,   RA   (   R'   R)   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR,   Ž   s    c         C@  sA   y |  j  j ƒ  } Wn t k
 r, d } n Xd | |  j  j f S(   NRE   s)   <BoundedSemaphore(value=%s, maxvalue=%s)>(   R   RC   RF   R*   (   R'   R)   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyRG   ‘   s    
(   R<   R=   R,   RG   (    (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR   Œ   s   c           B@  s    e  Z d  Z d „  Z d „  Z RS(   s   
    Non-recursive lock.
    c         C@  s   t  j |  t d d ƒ d  S(   Ni   (   R   R,   RA   (   R'   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR,   Ÿ   s    c         C@  sµ   y“ |  j  j ƒ  rP t ƒ  j } t j ƒ  j d k r’ | d t j ƒ  j 7} q’ nB |  j  j ƒ  d k rn d } n$ |  j  j ƒ  d k rŒ d } n d } Wn t k
 r¬ d } n Xd	 | S(
   Nt
   MainThreadt   |i   R%   i    t   SomeOtherThreadt   SomeOtherProcessRE   s   <Lock(owner=%s)>(	   R   t   _is_mineR   R   t	   threadingt   currentThreadRC   t   _countRF   (   R'   R   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyRG   ¢   s    		

(   R<   R=   t   __doc__R,   RG   (    (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR   š   s   	c           B@  s    e  Z d  Z d „  Z d „  Z RS(   s   
    Recursive lock
    c         C@  s   t  j |  t d d ƒ d  S(   Ni   (   R   R,   t   RECURSIVE_MUTEX(   R'   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR,   ¸   s    c         C@  sâ   y´ |  j  j ƒ  r_ t ƒ  j } t j ƒ  j d k rM | d t j ƒ  j 7} n  |  j  j ƒ  } nT |  j  j ƒ  d k rƒ d \ } } n0 |  j  j ƒ  d k r§ d \ } } n d \ } } Wn t k
 rÓ d \ } } n Xd
 | | f S(   NRH   RI   i   R%   i    RJ   t   nonzeroRK   RE   s   <RLock(%s, %s)>(   R%   i    (   RJ   RR   (   RK   RR   (   RE   RE   (	   R   RL   R   R   RM   RN   RO   RC   RF   (   R'   R   R?   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyRG   »   s    (   R<   R=   RP   R,   RG   (    (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR   ³   s   	c           B@  sz   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d d „ Z d	 „  Z d
 „  Z d d „ Z RS(   s   
    Condition variable
    c         C@  sM   | p t  ƒ  |  _ t d ƒ |  _ t d ƒ |  _ t d ƒ |  _ |  j ƒ  d  S(   Ni    (   R   t   _lockR   t   _sleeping_countt   _woken_countt   _wait_semaphoreR$   (   R'   t   lock(    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR,   Ò   s
    c         C@  s&   t  |  ƒ |  j |  j |  j |  j f S(   N(   R	   RS   RT   RU   RV   (   R'   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR4   Ù   s    
c         C@  s,   | \ |  _  |  _ |  _ |  _ |  j ƒ  d  S(   N(   RS   RT   RU   RV   R$   (   R'   R3   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR6   Þ   s    c         C@  s   |  j  j ƒ  S(   N(   RS   R/   (   R'   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR/   ã   s    c         G@  s   |  j  j | Œ  S(   N(   RS   R0   (   R'   R1   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR0   æ   s    c         C@  s"   |  j  j |  _ |  j  j |  _ d  S(   N(   RS   R-   R.   (   R'   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR$   é   s    c         C@  sQ   y& |  j  j j ƒ  |  j j j ƒ  } Wn t k
 r? d } n Xd |  j | f S(   Nt   unkowns   <Condition(%s, %s)>(   RT   R   RC   RU   RF   RS   (   R'   t   num_waiters(    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyRG   í   s    
c         C@  s³   |  j  j j ƒ  s t d ƒ ‚ |  j j ƒ  |  j  j j ƒ  } x! t | ƒ D] } |  j  j ƒ  qJ Wz |  j j	 t
 | ƒ } Wd  |  j j ƒ  x! t | ƒ D] } |  j  j	 ƒ  q— W| SX(   Ns,   must acquire() condition before using wait()(   RS   R   RL   t   AssertionErrorRT   R.   RO   R   RV   R-   t   TrueRU   (   R'   t   timeoutR?   t   it   ret(    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt   waitõ   s    	c         C@  s±   |  j  j j ƒ  s t d ƒ ‚ |  j j t ƒ s7 t ‚ x4 |  j j t ƒ rm |  j j t ƒ } | s: t ‚ q: W|  j j t ƒ r­ |  j j	 ƒ  |  j j ƒ  |  j j t ƒ n  d  S(   Ns   lock is not owned(
   RS   R   RL   RZ   RV   R-   t   FalseRU   RT   R.   (   R'   t   res(    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt   notify  s    c         C@  sî   |  j  j j ƒ  s t d ƒ ‚ |  j j t ƒ s7 t ‚ x4 |  j j t ƒ rm |  j j t ƒ } | s: t ‚ q: Wd } x- |  j j t ƒ r£ |  j j	 ƒ  | d 7} qw W| rê x! t
 | ƒ D] } |  j j ƒ  q· Wx |  j j t ƒ ræ qÑ Wn  d  S(   Ns   lock is not ownedi    i   (   RS   R   RL   RZ   RV   R-   R`   RU   RT   R.   R   (   R'   Ra   t   sleepersR]   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt
   notify_all  s    c         C@  sŽ   | ƒ  } | r | S| d  k	 r/ t ƒ  | } n d  } d  } xL | s‰ | d  k	 rp | t ƒ  } | d k rp Pqp n  |  j | ƒ | ƒ  } q> W| S(   Ni    (   R%   R   R_   (   R'   t	   predicateR\   t   resultt   endtimet   waittime(    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt   wait_for5  s    		N(   R<   R=   RP   R%   R,   R4   R6   R/   R0   R$   RG   R_   Rb   Rd   Ri   (    (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR   Í   s   								c           B@  s8   e  Z d  „  Z d „  Z d „  Z d „  Z d d „ Z RS(   c         C@  s%   t  t ƒ  ƒ |  _ t d ƒ |  _ d  S(   Ni    (   R   R   t   _condR   t   _flag(   R'   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR,   J  s    c         C@  sM   |  j  j ƒ  z+ |  j j t ƒ r3 |  j j ƒ  t St SWd  |  j  j ƒ  Xd  S(   N(   Rj   R-   Rk   R`   R.   R[   (   R'   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt   is_setN  s    c         C@  sP   |  j  j ƒ  z. |  j j t ƒ |  j j ƒ  |  j  j ƒ  Wd  |  j  j ƒ  Xd  S(   N(   Rj   R-   Rk   R`   R.   Rd   (   R'   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt   setX  s    c         C@  s6   |  j  j ƒ  z |  j j t ƒ Wd  |  j  j ƒ  Xd  S(   N(   Rj   R-   Rk   R`   R.   (   R'   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt   cleara  s    c         C@  s   |  j  j ƒ  z] |  j j t ƒ r2 |  j j ƒ  n |  j  j | ƒ |  j j t ƒ re |  j j ƒ  t St SWd  |  j  j ƒ  Xd  S(   N(   Rj   R-   Rk   R`   R.   R_   R[   (   R'   R\   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR_   h  s    N(   R<   R=   R,   Rl   Rm   Rn   R%   R_   (    (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR   H  s
   		
			R   c         C@  st   |  j  d ƒ t d d ƒ }  t |  ƒ d k r= t d ƒ ‚ n  t ƒ  } t j | |  ƒ } | t |  ƒ k sp t ‚ d  S(   Nt   asciis    i   s   name too long(   t   encodeR   t   lent
   ValueErrort   _get_unlinkfdR8   t   writeRZ   (   R   t   fdt   bits(    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR&   ~  s    	c          C@  s«   t  ƒ  }  |  j d  k r¤ t j ƒ  \ } } t j ƒ  } | d k r‹ y% d d l m } | d |  j ƒ Wn n Xt | ƒ t j	 d ƒ n  t j
 | ƒ | |  _ n  |  j S(   Ni    (   t   setproctitles   [sem_cleanup for %r](   R   t	   _unlinkfdR%   R8   t   pipet   forkRw   t   pidt   _collect_names_then_unlinkt   _exitt   close(   t   cpt   rt   wR{   Rw   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyRs   ˆ  s    	
c         C@  s  t  j  t  j t  j ƒ t  j  t  j t  j ƒ y t j d ƒ } Wn d } n Xt d |  ƒ t |  d | ƒ g  } x; y t j |  d ƒ } Wn qv X| s  Pn  | j | ƒ qv WxS t	 d d ƒ j
 | ƒ j t	 d d ƒ ƒ D]' } y t | j d ƒ ƒ WqÜ qÜ XqÜ Wd  S(	   Nt   SC_OPEN_MAXi   i    i   i   t    Ro   s    (   t   signalt   SIGINTt   SIG_IGNt   SIGTERMR8   t   sysconfR   t   readt   appendR   t   joint   splitR   t   decode(   R€   t   MAXFDt   datat   sR   (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyR|   Ÿ  s,    
1(0   t
   __future__R    R>   R8   R„   R    RM   t   _extR   R   t   fiveR   R   t   processR   t   utilR   R   R   R   R	   R
   t   compatR   R   t   __all__t   listRQ   RA   R   RB   R   R   t   _multiprocessingt   ImportErrorR%   R   t   objectR   R   R   R   R   R   R!   R&   Rs   R|   (    (    (    s6   /tmp/pip-unpacked-wheel-40MfcW/billiard/synchronize.pyt   <module>	   sD   	>{0	
	