
    Sfg                         d 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 G d de          Z ee          Zdd
ZddZddZddZd ZddZd ZdS )zZ
    billiard._win
    ~~~~~~~~~~~~~

    Windows utilities to terminate process groups.

    N)	byrefsizeofwindll	StructureWinErrorPOINTERc_size_tc_charc_void_p)DWORDLONG   c                   T    e Zd 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z  fg
ZdS )PROCESSENTRY32dwSizecntUsageth32ProcessIDth32DefaultHeapIDth32ModuleID
cntThreadsth32ParentProcessIDpcPriClassBasedwFlags	szExeFilei  N)__name__
__module____qualname__r   r	   r   r
   _fields_     ?/var/www/html/env/lib/python3.11/site-packages/billiard/_win.pyr   r      si        	5	U	% 	h'		u	&	4 	E	fsl#HHHr!   r      c                 x    t           j                            | |          }|t          k    rt	                      |S N)r   kernel32CreateToolhelp32SnapshotINVALID_HANDLE_VALUEr   )r   r   	hSnapshots      r"   r'   r'   +   s<    889FH HI(((jjr!   c                 B    t          t          j        j        | |          S r%   )_Process32nr   r&   Process32Firstr)   pes     r"   r,   r,   3   s    v5y"EEEr!   c                 B    t          t          j        j        | |          S r%   )r+   r   r&   Process32Nextr-   s     r"   r0   r0   7   s    v4iDDDr!   c                     |t                      }t          t                     |_         | |t          |                    }|s7t          j                                        t          k    rd S t                      |S r%   )	r   r   r   r   r   r&   GetLastErrorERROR_NO_MORE_FILESr   )funr)   r.   successs       r"   r+   r+   ;   sn    	z~&&BIc)U2YY''G ?''))-@@@FjjIr!   c                      t                      } i }t          |           }|r(|j        r|j        ||j        <   t	          | |          }|(|S )z}Return a dictionary with all processes pids as keys and their
       parents as value. Ignore processes with no parents.
    )r'   r,   r   r   r0   )hparentsr.   s      r"   get_all_processes_pidsr9   G   sd     	!""AG			B
 "! 	?(*(>GB$%1b!!  "
 Nr!   Tc                 \   t                      }t          |                                          }| h}	 |                                }|D ]!}||         |v r|                    |           "||k    rn|                                }T|s|                    |            t          |          S )z1Return a list with all the pids of a process tree)r9   listkeyscopyaddremove)pidinclude_parentr8   all_pidspidspids_new_pids          r"   get_processtree_pidsrF   V   s    $&&GGLLNN##H5D
99;; 	# 	#Dt}$$T"""t}}
  C::r!   c                 X    t          |           }|D ]}t          j        ||           dS )z&Kill a process and all its descendantsN)rF   oskill)r@   signumfamily_pidsrE   s       r"   kill_processtreerL   m   s=    &s++K  
f r!   )r#   r   r%   )T)__doc__rH   ctypesr   r   r   r   r   r   r	   r
   r   ctypes.wintypesr   r   r3   valuer(   r   LPPROCESSENTRY32r'   r,   r0   r+   r9   rF   rL   r    r!   r"   <module>rR      s    
			                     
 ( ' ' ' ' ' ' ' x||)     Y    7>**    F F F FE E E E	 	 	 	     .    r!   