o
    hg                     @   s   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 deZeeZdd
dZdddZdddZdddZdd ZdddZd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                   @   sP   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 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_ r   r   O/var/www/html/optinet_system/venv/lib/python3.10/site-packages/billiard/_win.pyr      s    
r      c                 C   s    t j| |}|tkrt |S N)r   kernel32CreateToolhelp32SnapshotINVALID_HANDLE_VALUEr   )r   r   	hSnapshotr   r   r   r#   +   s   r#   c                 C      t tjj| |S r!   )_Process32nr   r"   Process32Firstr%   per   r   r   r(   3      r(   c                 C   r&   r!   )r'   r   r"   Process32Nextr)   r   r   r   r,   7   r+   r,   c                 C   sF   |d u rt  }tt |_| |t|}|s!tj tkrd S t |S r!   )	r   r   r   r   r   r"   GetLastErrorERROR_NO_MORE_FILESr   )funr%   r*   successr   r   r   r'   ;   s   
r'   c                  C   s:   t  } i }t| }|r|jr|j||j< t| |}|s|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   r,   )hparentsr*   r   r   r   get_all_processes_pidsG   s   
r3   Tc                 C   sl   t  }t| }| h}	 | }|D ]}|| |v r || q||kr&n| }q|s2||  t|S )z1Return a list with all the pids of a process tree)r3   listkeyscopyaddremove)pidinclude_parentr2   all_pidspidspids_new_pidr   r   r   get_processtree_pidsV   s    

r?   c                 C   s"   t | }|D ]}t|| qdS )z&Kill a process and all its descendantsN)r?   oskill)r9   signumfamily_pidsr>   r   r   r   kill_processtreem   s   rD   )r    r   r!   )T)__doc__r@   ctypesr   r   r   r   r   r   r   r	   r
   ctypes.wintypesr   r   r.   valuer$   r   LPPROCESSENTRY32r#   r(   r,   r'   r3   r?   rD   r   r   r   r   <module>   s    ,





