o
    h                     @   sV   d Z ddlZddlZddlZddlZddlmZ eeZ	d
dede
ddfdd	ZdS )z;
POSIX-specific functionality for stdio client operations.
    N)Process       @processtimeout_secondsreturnc                    s  t | ddpt t | dddd}|sdS zUt|}t|tj t|% 	 zt|d tdI dH  W n t	yJ   Y W d   W dS w q)1 sOw   Y  zt|tj
 W W dS  t	yj   Y W dS w  t	ttfy } zgtd| d| d	 z"|   t| |  I dH  W d   n1 sw   Y  W n* ty   td
| d z|   W n ty   td|  Y nw Y nw W Y d}~dS W Y d}~dS d}~ww )a  
    Terminate a process and all its children on POSIX systems.

    Uses os.killpg() for atomic process group termination.

    Args:
        process: The process to terminate
        timeout_seconds: Timeout in seconds before force killing (default: 2.0)
    pidNpopenTr   g?z)Process group termination failed for PID z: z", falling back to simple terminatez#Process termination failed for PID z, attempting force killzFailed to kill process )getattrosgetpgidkillpgsignalSIGTERManyiomove_on_aftersleepProcessLookupErrorSIGKILLPermissionErrorOSErrorloggerwarning	terminate
fail_afterwait	Exceptionkill	exception)r   r   r   pgide r    W/var/www/html/openai_agents/venv/lib/python3.10/site-packages/mcp/os/posix/utilities.pyterminate_posix_process_tree   sT    

	r"   )r   )__doc__loggingr
   r   r   	anyio.abcr   	getLogger__name__r   floatr"   r    r    r    r!   <module>   s    
