ó
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 Z d  d l	 m
 Z d d l m Z y d  d l m Z Wn e k
 r± d Z n Xd d l m Z m Z y e j j e j ƒ  ƒ Z Wn e k
 rý d Z n Xd d	 d
 g Z d „  Z d „  Z d „  Z d „  Z e d „ Z d e  f d „  ƒ  YZ! d e f d „  ƒ  YZ" d e! f d „  ƒ  YZ# e# ƒ  a$ [# i  Z% xG e e j& ƒ D]6 \ Z' Z( e' d  d k r¡d e' k r¡e' e% e( <q¡q¡We d k	 rðe ƒ  n d Z) d S(   i    (   t   absolute_importN(   t   processi   (   t   bytes(   t   WeakSet(   t   itemst   string_tt   Processt   current_processt   active_childrenc           C@  s   t  S(   s@   
    Return process object representing the current process
    (   t   _current_process(    (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyR   ,   s    c         C@  s   |  a  t _  d  S(   N(   R	   t   _mproc(   R   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   _set_current_process3   s    c          C@  sU   t  d  k	 rQ xB t t  j ƒ D]. }  |  j j ƒ  d  k	 r t  j j |  ƒ q q Wn  d  S(   N(   R	   t   Nonet   listt	   _childrent   _popent   pollt   discard(   t   p(    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   _cleanup8   s    c         C@  s/   y |  j  ƒ  Wn t t t f k
 r* n Xd  S(   N(   t   flusht   AttributeErrort   EnvironmentErrort   NotImplementedError(   t   f(    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   _maybe_flush@   s    c         C@  s=   y |  ƒ  Wn t  k
 r g  SXt d k	 r9 t t j ƒ Sg  S(   sN   
    Return list of process objects corresponding to live child processes
    N(   t	   TypeErrorR	   R   R   R   (   R   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyR   G   s    c           B@  s  e  Z d  Z d Z d d d d i  d d „ Z d „  Z d „  Z d „  Z d d „ Z	 d „  Z
 d „  Z d „  Z d	 „  Z e e e ƒ Z d
 „  Z d „  Z e e e ƒ Z d „  Z d „  Z e e e ƒ Z e d „  ƒ Z e d „  ƒ Z e Z e d „  ƒ Z d „  Z d „  Z RS(   s€   
    Process objects represent activity that is run in a separate process

    The class is analagous to `threading.Thread`
    c   	      K@  s#  | d  k s t d ƒ ‚ t t j ƒ } t j | f |  _ t j |  _ | d  k	 r^ | |  _ n t j |  _ t j |  _ t j	 |  _	 t j
 |  _
 t j ƒ  |  _ d  |  _ | |  _ t | ƒ |  _ t | ƒ |  _ | pý t |  ƒ j d d j d „  |  j Dƒ ƒ |  _ t d  k	 rt j |  ƒ n  d  S(   Ns#   group argument must be None for nowt   -t   :c         s@  s   |  ] } t  | ƒ Vq d  S(   N(   t   str(   t   .0t   i(    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pys	   <genexpr>q   s    (   R   t   AssertionErrort   nextR	   t   _countert	   _identityt   _authkeyt	   _daemonict   _tempdirt
   _semprefixt	   _unlinkfdt   ost   getpidt   _parent_pidR   t   _targett   tuplet   _argst   dictt   _kwargst   typet   __name__t   joint   _namet	   _danglingt   add(	   t   selft   groupt   targett   namet   argst   kwargst   daemont   _kwt   count(    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   __init__]   s&    		 c         C@  s&   |  j  r" |  j  |  j |  j Ž  n  d S(   sQ   
        Method to be run in sub-process; can be overridden in sub-class
        N(   R,   R.   R0   (   R7   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   runv   s    	c         C@  s    |  j  d k s t d ƒ ‚ |  j t j ƒ  k s< t d ƒ ‚ t ƒ  |  j d k	 r^ |  j } n d d l m	 } | |  ƒ |  _  |  j  j
 |  _ t j j |  ƒ d S(   s%   
        Start child process
        s   cannot start a process twices:   can only start a process object created by current processi   (   t   PopenN(   R   R   R    R+   R)   R*   R   t   _Popent   forkingRB   t   sentinelt	   _sentinelR	   R   R6   (   R7   RB   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   start}   s    	c         C@  s   |  j  j ƒ  d S(   sT   
        Terminate process; sends SIGTERM signal or uses TerminateProcess()
        N(   R   t	   terminate(   R7   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyRH      s    c         C@  sq   |  j  t j ƒ  k s! t d ƒ ‚ |  j d k	 s< t d ƒ ‚ |  j j | ƒ } | d k	 rm t j j	 |  ƒ n  d S(   s5   
        Wait until child process terminates
        s   can only join a child processs   can only join a started processN(
   R+   R)   R*   R    R   R   t   waitR	   R   R   (   R7   t   timeoutt   res(    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyR3   “   s
    !c         C@  sa   |  t  k r t S|  j t j ƒ  k s1 t d ƒ ‚ |  j d k rD t S|  j j	 ƒ  |  j j
 d k S(   s1   
        Return whether process is alive
        s   can only test a child processN(   R	   t   TrueR+   R)   R*   R    R   R   t   FalseR   t
   returncode(   R7   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   is_alive   s    !c         C@  s&   |  j  d  k r t S|  j  j ƒ  d  k S(   N(   R   R   RM   R   (   R7   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt	   _is_alive©   s    c         C@  s   |  j  S(   N(   R4   (   R7   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt	   _get_name®   s    c         C@  s(   t  t t ƒ s t d ƒ ‚ | |  _ d  S(   Ns   name must be a string(   t
   isinstanceR:   R   R    R4   (   R7   t   value(    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt	   _set_name±   s    c         C@  s   |  j  S(   N(   R%   (   R7   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   _get_daemon¶   s    c         C@  s(   |  j  d  k s t d ƒ ‚ | |  _ d  S(   Ns   process has already started(   R   R   R    R%   (   R7   t   daemonic(    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   _set_daemon¹   s    c         C@  s   |  j  S(   N(   R$   (   R7   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   _get_authkey¾   s    c         C@  s   t  | ƒ |  _ d  S(   N(   t   AuthenticationStringR$   (   R7   t   authkey(    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   _set_authkeyÁ   s    c         C@  s#   |  j  d k r |  j  S|  j  j ƒ  S(   sM   
        Return exit code of process or `None` if it has yet to stop
        N(   R   R   R   (   R7   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   exitcodeÅ   s    c         C@  s-   |  t  k r t j ƒ  S|  j o( |  j j Sd S(   sU   
        Return identifier (PID) of process or `None` if it has yet to start
        N(   R	   R)   R*   R   t   pid(   R7   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   identÎ   s    
c         C@  s/   y |  j  SWn t k
 r* t d ƒ ‚ n Xd S(   s{   
        Return a file descriptor (Unix) or handle (Windows) suitable for
        waiting for process termination.
        s   process not startedN(   RF   R   t
   ValueError(   R7   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyRE   Ú   s    c         C@  sá   |  t  k r d } n] |  j t j ƒ  k r3 d } n? |  j d  k rK d } n' |  j j ƒ  d  k	 rl |  j } n d } t | ƒ t	 k r² | d k r™ d } q² d t
 j | | ƒ } n  d t |  ƒ j |  j | |  j rÙ d pÜ d	 f S(
   Nt   startedt   unknownt   initiali    t   stoppeds   stopped[%s]s   <%s(%s, %s%s)>s    daemont    (   R	   R+   R)   R*   R   R   R   R\   R1   t   intt   _exitcode_to_namet   getR2   R4   R%   (   R7   t   status(    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   __repr__å   s    				c   
      C@  s¯  d d l  m } zgynt ƒ  |  _ t j d ƒ |  _ t j d  k	 rƒ y# t j j
 ƒ  t t j ƒ t _ Wqƒ t t f k
 r qƒ Xn  t } t |  ƒ t j j j } t | j ƒ  ƒ } | j d  ƒ xV | D]N } | sì t | | t j ƒ rÈ x' t j | ƒ j D] } | j ƒ  qÿ WqÈ qÈ Wt j ƒ  t _  z | j! j" ƒ  | j# ƒ  Wd  ~ X| j$ d |  j% ƒ z |  j& ƒ  d } Wd  | j' ƒ  XWnò t( k
 r} | j) s¥d } qvt | j) d t* ƒ rË| j) d } qvt j+ j, t- | j) d ƒ d ƒ t. t j+ ƒ t | j) d t- ƒ rd n d } nX d } | j/ d |  j0 d t1 ƒsvd d  l2 }	 t j+ j, d |  j0 ƒ |	 j3 ƒ  qvn XWd  | j$ d	 |  j% | ƒ t. t j4 ƒ t. t j+ ƒ X| S(
   Ni   (   t   utils#   child process %s calling self.run()i    s   
s
   Process %st   exc_infos   Process %s:
s#   process %s exiting with exitcode %d(5   Rd   Rj   t   setR   t	   itertoolsR?   R"   t   syst   stdinR   t   closet   openR)   t   devnullt   OSErrorR_   R	   R   t   loggingt   Loggert   managert
   loggerDictR   t   keyst   appendRR   t   PlaceHoldert	   getLoggert   handlerst
   createLockt	   threadingt   RLockt   _lockt   _finalizer_registryt   cleart   _run_after_forkerst   infoR]   RA   t   _exit_functiont
   SystemExitR;   Re   t   stderrt   writeR   R   t   errorR:   RL   t	   tracebackt	   print_exct   stdout(
   R7   Rj   t   old_processRw   t   logger_namesR:   t   handlerR\   t   excRŠ   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt
   _bootstrapý   sd     


		!%	N(    (   R2   t
   __module__t   __doc__R   RC   R@   RA   RG   RH   R3   RO   RP   RQ   RT   t   propertyR:   RU   RW   R=   RX   R[   RZ   R\   R^   R]   RE   Ri   R‘   (    (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyR   U   s2   				
									
	RY   c           B@  s   e  Z d  „  Z RS(   c         C@  s>   d d l  m } | j ƒ  s+ t d ƒ ‚ n  t t |  ƒ f f S(   Ni   (   RB   sJ   Pickling an AuthenticationString object is disallowed for security reasons(   RD   RB   t   thread_is_spawningR   RY   R   (   R7   RB   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt
   __reduce__E  s
    (   R2   R’   R–   (    (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyRY   C  s   t   _MainProcessc           B@  s   e  Z d  „  Z RS(   c         C@  s¡   d |  _  t |  _ d |  _ d  |  _ d  |  _ t j d ƒ |  _	 t
 ƒ  |  _ t t j d ƒ ƒ |  _ d  |  _ d t j t j d ƒ ƒ j d ƒ |  _ d  |  _ d  S(   Nt   MainProcessi   i    s   mp-i   t   ascii(    (   R#   RM   R%   R4   R   R+   R   Rm   R?   R"   Rl   R   RY   R)   t   urandomR$   R&   t   binasciit   hexlifyt   decodeR'   R(   (   R7   (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyR@   U  s    							(   R2   R’   R@   (    (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyR—   S  s   i   t   SIGt   _(*   t
   __future__R    R)   Rn   t   signalRm   R›   Rt   R~   t   multiprocessingR   R
   t   compatR   t   _weakrefsetR   t   ImportErrorR   t   fiveR   R   t   patht   abspatht   getcwdt   ORIGINAL_DIRRs   t   __all__R   R   R   R   R   t   objectR   RY   R—   R	   Rf   t   __dict__R:   t   signumR5   (    (    (    s2   /tmp/pip-unpacked-wheel-40MfcW/billiard/process.pyt   <module>	   sD   

				î	