o SbM@sdZddlZddlZddlZddlZdZejeZ ddZ ddZ ej dkr3e ed d Zd d ZdSd dZddZdd ZedkrjeedrXzeWn eyWYnwe eejddeddSdS)zSupport 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 cCs&z|j|dWStjyYdSw)z,Implement wait timeout support for Python 3.)timeoutN)wait subprocessTimeoutExpired)popenrr5/tmp/pip-target-onvjaxws/lib/python/pymongo/daemon.py _popen_wait s r cCs|dur d|_dSdS)zpSilence Popen's ResourceWarning. Note this should only be used if the process was created as a daemon. Nr) returncode)rrrr _silence_resource_warning)s r win32ZDETACHED_PROCESSc Csz)ttjd}tj|t|||d}t|WdWdS1s"wYWdStyL}ztj d|dd|t ddWYd}~dSd}~ww) z!Spawn a daemon process (Windows).r+b) creationflagsstdinstderrstdoutNFailed to start r+: is it on your $PATH? Original exception:  stacklevel) openosdevnullrPopen_DETACHED_PROCESSr FileNotFoundErrorwarningswarnRuntimeWarning)argsrrexcrrr _spawn_daemon;s& & r$c Csz$ttjd}tj|d|||dWdWS1swYWdStyG}ztjd|dd|tdd WYd}~dSd}~ww) z,Spawn the process and silence stdout/stderr.rT) close_fdsrrrNrrrrr) rrrrrrrr r!)r"rr#rrr _spawnZs (r&cCs0tjtg}||tj|dd}t|tdS)z7Spawn a daemon process using a double subprocess.Popen.T)r%N)sys executable _THIS_FILEextendrrr _WAIT_TIMEOUT)r"Z spawner_argsZ temp_procrrr _spawn_daemon_double_popenhs  r,cCstjr t|dSt|dS)zSpawn a daemon process (Unix).N)r'r(r,r&)r"rrr r$qs  __main__setsid)__doc__rrr'rr+pathrealpath__file__r)r r platformgetattrrr$r&r,__name__hasattrr.OSErrorargv_exitrrrr s2