ķ
O'^c           @@  s  d  Z  d d l m Z d d l Z d d l m Z m Z m Z m Z m	 Z	 m
 Z
 m Z m Z m Z d d l m Z m Z d Z e d  j Z d e f d	     YZ e
 e  Z d
 d d  Z d d  Z d d  Z d d  Z d   Z e d  Z d   Z d S(   sZ   
    billiard._win
    ~~~~~~~~~~~~~

    Windows utilities to terminate process groups.

i    (   t   absolute_importN(	   t   byreft   sizeoft   windllt	   Structuret   WinErrort   POINTERt   c_size_tt   c_chart   c_void_p(   t   DWORDt   LONGi   i˙˙˙˙t   PROCESSENTRY32c           B@  sl   e  Z d  e f d e f d e f d e f d e f d e f d e f d e f d e f d	 e d
 f g
 Z RS(   t   dwSizet   cntUsaget   th32ProcessIDt   th32DefaultHeapIDt   th32ModuleIDt
   cntThreadst   th32ParentProcessIDt   pcPriClassBaset   dwFlagst	   szExeFilei  (   t   __name__t
   __module__R
   R   R   R   t   _fields_(    (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/_win.pyR      s   									i   c         C@  s1   t  j j |  |  } | t k r- t    n  | S(   N(   R   t   kernel32t   CreateToolhelp32Snapshott   INVALID_HANDLE_VALUER   (   R   R   t	   hSnapshot(    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/_win.pyR   -   s
    	c         C@  s   t  t j j |  |  S(   N(   t   _Process32nR   R   t   Process32First(   R   t   pe(    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/_win.pyR   5   s    c         C@  s   t  t j j |  |  S(   N(   R   R   R   t   Process32Next(   R   R    (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/_win.pyR!   9   s    c         C@  sk   | d  k r t   } n  t t  | _ |  | t |   } | sg t j j   t k r[ d  St	    n  | S(   N(
   t   NoneR   R   R   R   R   R   t   GetLastErrort   ERROR_NO_MORE_FILESR   (   t   funR   R    t   success(    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/_win.pyR   =   s    c          C@  sW   t    }  i  } t |   } x5 | rR | j r@ | j | | j <n  t |  |  } q W| S(   s}   Return a dictionary with all processes pids as keys and their
       parents as value. Ignore processes with no parents.
    (   R   R   R   R   R!   (   t   ht   parentsR    (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/_win.pyt   get_all_processes_pidsI   s    			c         C@  sĒ   t    } t | j    } t |  g  } x] | j   } x. | D]& } | | | k r@ | j |  q@ q@ W| | k rz Pn  | j   } q- W| s  | j |   n  t |  S(   s1   Return a list with all the pids of a process tree(   R)   t   listt   keyst   sett   copyt   addt   remove(   t   pidt   include_parentR(   t   all_pidst   pidst   pids_newt   _pid(    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/_win.pyt   get_processtree_pidsX   s    	c         C@  s1   t  |   } x | D] } t j | |  q Wd S(   s&   Kill a process and all its descendantsN(   R6   t   ost   kill(   R0   t   signumt   family_pidsR5   (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/_win.pyt   kill_processtreeo   s    (   t   __doc__t
   __future__R    R7   t   ctypesR   R   R   R   R   R   R   R   R	   t   ctypes.wintypesR
   R   R$   t   valueR   R   t   LPPROCESSENTRY32R   R"   R   R!   R   R)   t   TrueR6   R;   (    (    (    s/   /tmp/pip-unpacked-wheel-40MfcW/billiard/_win.pyt   <module>   s   @	