o
    svXj¦  ã                   @   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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.

é    )Úabsolute_importN)	Ú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   úJ/var/www/html/myproject/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)   5   ó   r)   c                 C   r'   r"   )r(   r   r#   ÚProcess32Nextr*   r   r   r    r-   9   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_pidsI   s   
ýr4   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)r4   ÚlistÚkeysÚcopyÚaddÚremove)ÚpidÚinclude_parentr3   Úall_pidsÚpidsÚpids_newÚ_pidr   r   r    Úget_processtree_pidsX   s    
€ö
r@   c                 C   s"   t | ƒ}|D ]}t ||¡ qdS )z&Kill a process and all its descendantsN)r@   ÚosÚkill)r:   ÚsignumÚfamily_pidsr?   r   r   r    Úkill_processtreeo   s   ÿrE   )r!   r   r"   )T)Ú__doc__Ú
__future__r   rA   Úctypesr   r   r   r   r   r   r	   r
   r   Úctypes.wintypesr   r   r/   Úvaluer%   r   ÚLPPROCESSENTRY32r$   r)   r-   r(   r4   r@   rE   r   r   r   r    Ú<module>   s    ,





