PYTHON-2234 Only rely on standard library in daemon.py (#597)
This commit is contained in:
parent
aaba51d927
commit
d06f3f3504
@ -22,13 +22,14 @@ client-side field level encryption is enabled. See
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
from pymongo.errors import PyMongoError
|
||||
|
||||
# The maximum amount of time to wait for the intermediate subprocess.
|
||||
_WAIT_TIMEOUT = 10
|
||||
_THIS_FILE = os.path.realpath(__file__)
|
||||
|
||||
|
||||
def _popen_wait(popen, timeout):
|
||||
"""Implement wait timeout support for Python 3."""
|
||||
try:
|
||||
@ -47,7 +48,9 @@ def _silence_resource_warning(popen):
|
||||
# "ResourceWarning: subprocess XXX is still running".
|
||||
# See https://bugs.python.org/issue38890 and
|
||||
# https://bugs.python.org/issue26741.
|
||||
popen.returncode = 0
|
||||
# popen is None when mongocryptd spawning fails
|
||||
if popen is not None:
|
||||
popen.returncode = 0
|
||||
|
||||
|
||||
if sys.platform == 'win32':
|
||||
@ -64,8 +67,9 @@ if sys.platform == 'win32':
|
||||
stdin=devnull, stderr=devnull, stdout=devnull)
|
||||
_silence_resource_warning(popen)
|
||||
except FileNotFoundError as exc:
|
||||
raise PyMongoError(
|
||||
f'Failed to start {args[0]}: is it on your $PATH?\nOriginal exception: {exc}')
|
||||
warnings.warn(f'Failed to start {args[0]}: is it on your $PATH?\n'
|
||||
f'Original exception: {exc}', RuntimeWarning,
|
||||
stacklevel=2)
|
||||
else:
|
||||
# On Unix we spawn the daemon process with a double Popen.
|
||||
# 1) The first Popen runs this file as a Python script using the current
|
||||
@ -87,8 +91,10 @@ else:
|
||||
close_fds=True,
|
||||
stdin=devnull, stderr=devnull, stdout=devnull)
|
||||
except FileNotFoundError as exc:
|
||||
raise PyMongoError(
|
||||
f'Failed to start {args[0]}: is it on your $PATH?\nOriginal exception: {exc}')
|
||||
warnings.warn(f'Failed to start {args[0]}: is it on your $PATH?\n'
|
||||
f'Original exception: {exc}', RuntimeWarning,
|
||||
stacklevel=2)
|
||||
|
||||
|
||||
def _spawn_daemon_double_popen(args):
|
||||
"""Spawn a daemon process using a double subprocess.Popen."""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user