ó
è¾bc           @   s  g  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	 m
 Z
 m Z m Z d  d l m Z m Z m Z d  d l m Z m Z e j d k pÁ e e d ƒ sÓ e d ƒ ‚ n  e j d k rd  d l Z d  d	 l m Z d
 „  Z d „  Z n d „  Z d „  Z e ƒ  a d „  Z e d ƒ e e e ƒ d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ e j% e j& e# ƒ d d „ Z' d „  Z( d „  Z) e j% e j e( ƒ e j d k rÿd „  Z* d „  Z+ e j% e j, e* ƒ n  d S(   iÿÿÿÿN(   t   current_process(   t   Popent	   duplicatet   closet   ForkingPickler(   t   register_after_forkt   debugt	   sub_debug(   t   Clientt   Listenert   win32t   recvfds%   pickling of connections not supported(   R
   c         C   sJ   t  j t  j t | ƒ } z  t | | ƒ } |  j | ƒ Wd  t | ƒ Xd  S(   N(   R
   t   OpenProcesst   PROCESS_ALL_ACCESSt   FalseR   t   sendR   (   t   connt   handlet   destination_pidt   process_handlet
   new_handle(    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyt   send_handleA   s    c         C   s
   |  j  ƒ  S(   N(   t   recv(   R   (    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyt   recv_handleK   s    c         C   s   t  j |  j ƒ  | ƒ d  S(   N(   t   _multiprocessingt   sendfdt   fileno(   R   R   R   (    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyR   O   s    c         C   s   t  j |  j ƒ  ƒ S(   N(   R   R   R   (   R   (    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyR   R   s    c         C   s;   x t  D] } t | ƒ q Wt  j ƒ  t j ƒ  a d  a d  S(   N(   t   _cacheR   t   cleart	   threadingt   Lockt   _lockt   Nonet	   _listener(   t   objt   h(    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyt   _reset[   s
    
c          C   s‚   t  d  k r~ t j ƒ  zW t  d  k rl t d ƒ t d t ƒ  j ƒ a  t j	 d t
 ƒ }  t |  _ |  j ƒ  n  Wd  t j ƒ  Xn  t  S(   Ns0   starting listener and thread for sending handlest   authkeyt   target(   R!   R    R   t   acquireR   R	   R    R%   R   t   Threadt   _servet   Truet   daemont   startt   release(   t   t(    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyt   _get_listenerf   s    

	c          C   s¾   d d l  m }  m } x¡ yS t j ƒ  } | j ƒ  \ } } t j | ƒ t | | | ƒ t	 | ƒ | j	 ƒ  Wq |  ƒ  s¶ d d  l
 } | d d d d | j ƒ  d d ƒ q¶ q Xq Wd  S(   Ni   (   t
   is_exitingt   sub_warningiÿÿÿÿs.   thread for sharing handles raised exception :
t   -iO   s   
(   t   utilR0   R1   R!   t   acceptR   R   t   removeR   R   t	   tracebackt
   format_exc(   R0   R1   R   t   handle_wantedR   R6   (    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyR)   w   s    
	c         C   s[   t  j ƒ  r" d  t  j |  ƒ t f St |  ƒ } t j | ƒ t d |  ƒ t	 ƒ  j
 | t f S(   Ns   reducing handle %d(   R   t   thread_is_spawningR    t   duplicate_for_childR*   R   R   t   addR   R/   t   addressR   (   R   t
   dup_handle(    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyt   reduce_handleŽ   s    c         C   sq   |  \ } } } | r | St  d | ƒ t | d t ƒ  j ƒ} | j | t j ƒ  f ƒ t | ƒ } | j ƒ  | S(   Ns   rebuilding handle %dR%   (	   R   R   R    R%   R   t   ost   getpidR   R   (   t   pickled_dataR<   R   t	   inheritedR   R   (    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyt   rebuild_handle–   s    
c         C   s+   t  |  j ƒ  ƒ } t | |  j |  j f f S(   N(   R>   R   t   rebuild_connectiont   readablet   writable(   R   t   rh(    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyt   reduce_connection¥   s    c         C   s%   t  |  ƒ } t j | d | d | ƒS(   NRE   RF   (   RC   R   t
   Connection(   t   reduced_handleRE   RF   R   (    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyRD   ©   s    i    c         C   sC   t  j |  | | | ƒ } | j t  j  k	 r? t  j  d | ƒ } n  | S(   Nt   _sock(   t   sockett   fromfdt	   __class__(   t   fdt   familyt   type_t   protot   s(    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyRM   µ   s    c         C   s1   t  |  j ƒ  ƒ } t | |  j |  j |  j f f S(   N(   R>   R   t   rebuild_socketRP   t   typeRR   (   RS   RJ   (    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyt   reduce_socket»   s    c         C   s/   t  |  ƒ } t | | | | ƒ } t | ƒ | S(   N(   RC   RM   R   (   RJ   RP   RQ   RR   RO   RK   (    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyRT   ¿   s    
c         C   s+   t  |  j ƒ  ƒ } t | |  j |  j f f S(   N(   R>   R   t   rebuild_pipe_connectionRE   RF   (   R   RG   (    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyt   reduce_pipe_connectionÍ   s    c         C   s%   t  |  ƒ } t j | d | d | ƒS(   NRE   RF   (   RC   R   t   PipeConnection(   RJ   RE   RF   R   (    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyRW   Ñ   s    (-   t   __all__R?   t   sysRL   R   R   t   multiprocessingR    t   multiprocessing.forkingR   R   R   R   t   multiprocessing.utilR   R   R   t   multiprocessing.connectionR   R	   t   platformt   hasattrt   ImportErrort   _subprocessR
   R   R   t   setR   R$   R    R/   R)   R>   RC   RH   RD   t   registerRI   RM   RV   RT   RX   RW   RY   (    (    (    s/   /usr/lib/python2.7/multiprocessing/reduction.pyt   <module>$   sJ   "	
				
										