Check if subprocess module is patched directly

eventlet patches subprocess module since 0.35.2[1]. So we no longer
need that old workaround.

[1] 614a20462a

Change-Id: I75088e04cc3ba9a8bbb0a7af74650fc1ebff4c95
This commit is contained in:
Takashi Kajinami 2024-10-18 00:31:16 +09:00
parent 20f6fb1b6e
commit 2fe6b92906
3 changed files with 15 additions and 21 deletions

View File

@ -42,25 +42,19 @@ if os.name == 'nt':
category=DeprecationWarning)
# NOTE(bnemec): eventlet doesn't monkey patch subprocess, so we need to
# determine the proper subprocess module to use ourselves. I'm using the
# time module as the check because that's a monkey patched module we use
# in combination with subprocess below, so they need to match.
eventlet = importutils.try_import('eventlet')
eventlet_patched = eventlet and eventlet.patcher.is_monkey_patched(time)
if eventlet_patched:
if os.name == 'nt':
if eventlet:
from eventlet import tpool
eventlet_patched = (eventlet and
eventlet.patcher.is_monkey_patched('subprocess'))
if eventlet_patched and os.name == 'nt':
# subprocess.Popen.communicate will spawn two threads consuming
# stdout/stderr when passing data through stdin. We need to make
# sure that *native* threads will be used as pipes are blocking
# on Windows.
# Recent eventlet versions actually do patch subprocess.
subprocess = eventlet.patcher.original('subprocess')
subprocess.threading = eventlet.patcher.original('threading')
else:
from eventlet.green import subprocess
from eventlet import tpool
else:
import subprocess
@ -397,9 +391,9 @@ def execute(*cmd, **kwargs):
stderr=_PIPE,
close_fds=close_fds,
preexec_fn=on_preexec_fn,
shell=shell, # nosec:B604
shell=shell,
cwd=cwd,
env=env_variables)
env=env_variables) # nosec:B602
if on_execute:
on_execute(obj)

View File

@ -34,4 +34,4 @@ console_scripts =
[extras]
eventlet =
eventlet>=0.27.0 # MIT
eventlet>=0.35.2 # MIT

View File

@ -2,4 +2,4 @@ oslotest>=3.2.0 # Apache-2.0
coverage>=4.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD
stestr>=2.0.0 # Apache-2.0
eventlet>=0.27.0 # MIT
eventlet>=0.35.2 # MIT