o
    ¡D®fg  ã                   @   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   úF/home/ubuntu/webapp/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    ,





