o
    Åîï]X  ã                   @   sð   d Z ddlZddlZddlZddlZdZej e¡Z	ej
d dk r&dd„ Zndd„ Zdd	„ Zejd
kr?eeddƒZdd„ ZdS dd„ Zdd„ Zdd„ Zedkrveedƒrdze ¡  W n	 eyc   Y nw eeejdd… ƒƒ e d¡ dS dS )zßSupport for spawning a daemon process.

PyMongo only attempts to spawn the mongocryptd daemon process when automatic
client-side field level encryption is enabled. See
:ref:`automatic-client-side-encryption` for more info.
é    Né
   é   c                 C   sb   ddl m} |ƒ | }d}	 |  ¡ }|dur|S ||ƒ  }|dkr#dS t|d |dƒ}t |¡ q)z,Implement wait timeout support for Python 2.r   )Útimegü©ñÒMb@?TNé   g      à?)Úpymongo.monotonicr   ÚpollÚminÚsleep)ÚpopenÚtimeoutÚ_timeÚdeadlineÚdelayÚ
returncodeÚ	remaining© r   ú@/var/www/html/env/lib/python3.10/site-packages/pymongo/daemon.pyÚ_popen_wait    s   


ör   c                 C   s&   z| j |d�W S  tjy   Y dS w )z,Implement wait timeout support for Python 3.)r   N)ÚwaitÚ
subprocessÚTimeoutExpired)r
   r   r   r   r   r   3   s
   þc                 C   s
   d| _ dS )zpSilence Popen's ResourceWarning.

    Note this should only be used if the process was created as a daemon.
    r   N)r   )r
   r   r   r   Ú_silence_resource_warning<   s   
	r   Úwin32ÚDETACHED_PROCESSé   c                 C   sN   t tjdƒ�}tj| t|||d�}t|ƒ W d  ƒ dS 1 s w   Y  dS )z!Spawn a daemon process (Windows).úr+b)ÚcreationflagsÚstdinÚstderrÚstdoutN)ÚopenÚosÚdevnullr   ÚPopenÚ_DETACHED_PROCESSr   )Úargsr"   r
   r   r   r   Ú_spawn_daemonL   s   ý
"ûr&   c                 C   sD   t tjdƒ�}tj| d|||d�W  d  ƒ S 1 sw   Y  dS )z,Spawn the process and silence stdout/stderr.r   T)Ú	close_fdsr   r   r   N)r    r!   r"   r   r#   )r%   r"   r   r   r   Ú_spawn`   s   ý$ÿr(   c                 C   s0   t jtg}| | ¡ tj|dd�}t|tƒ dS )z7Spawn a daemon process using a double subprocess.Popen.T)r'   N)ÚsysÚ
executableÚ
_THIS_FILEÚextendr   r#   r   Ú_WAIT_TIMEOUT)r%   Úspawner_argsÚ	temp_procr   r   r   Ú_spawn_daemon_double_popeni   s   

r0   c                 C   s   t jr	t| ƒ dS t| ƒ dS )zSpawn a daemon process (Unix).N)r)   r*   r0   r(   )r%   r   r   r   r&   s   s   
Ú__main__Úsetsidé   )Ú__doc__r!   r   r)   r   r-   ÚpathÚrealpathÚ__file__r+   Úversion_infor   r   ÚplatformÚgetattrr$   r&   r(   r0   Ú__name__Úhasattrr2   ÚOSErrorÚargvÚ_exitr   r   r   r   Ú<module>   s6   
	
	

ÿõ