From 394fbf4f046bcaa4e0591238b9fc06f1769e6ac5 Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Fri, 26 Sep 2014 19:06:56 +0000 Subject: [PATCH] Remove hard dep on eventlet We don't want to force users of this library to pull in eventlet, so conditionally import it in processutils and only use subprocess from eventlet if the stdlib is monkey patched. eventlet doesn't monkey patch subprocess so we can't rely on it to do that for us. Also uses sleep from the stdlib time module since it will be monkey patched when eventlet is in use and the right version will be used. Change-Id: I0df528d5ad0d67d6bbc0e7c217ef2d7fa45cce9a --- oslo/concurrency/processutils.py | 22 ++++++++++++++++++---- requirements.txt | 2 -- test-requirements.txt | 2 ++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/oslo/concurrency/processutils.py b/oslo/concurrency/processutils.py index 95c94bb..4a388b6 100644 --- a/oslo/concurrency/processutils.py +++ b/oslo/concurrency/processutils.py @@ -25,14 +25,24 @@ import shlex import signal import time -from eventlet.green import subprocess -from eventlet import greenthread +from oslo.utils import importutils from oslo.utils import strutils import six from oslo.concurrency._i18n import _ +# 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') +if eventlet and eventlet.patcher.is_monkey_patched(time): + from eventlet.green import subprocess +else: + import subprocess + + LOG = logging.getLogger(__name__) @@ -242,12 +252,16 @@ def execute(*cmd, **kwargs): LOG.log(loglevel, _('%r failed. Retrying.'), sanitized_cmd) if delay_on_retry: - greenthread.sleep(random.randint(20, 200) / 100.0) + time.sleep(random.randint(20, 200) / 100.0) finally: # NOTE(termie): this appears to be necessary to let the subprocess # call clean something up in between calls, without # it two execute calls in a row hangs the second one - greenthread.sleep(0) + # NOTE(bnemec): termie's comment above is probably specific to the + # eventlet subprocess module, but since we still + # have to support that we're leaving the sleep. It + # won't hurt anything in the stdlib case anyway. + time.sleep(0) def trycmd(*args, **kwargs): diff --git a/requirements.txt b/requirements.txt index d9106bb..b2525ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,8 +4,6 @@ Babel>=1.3 iso8601>=0.1.9 -eventlet>=0.15.1 -greenlet>=0.3.2 fixtures>=0.3.14 oslo.config>=1.4.0 # Apache-2.0 oslo.i18n>=1.0.0 # Apache-2.0 diff --git a/test-requirements.txt b/test-requirements.txt index 66960ea..11a1812 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -9,3 +9,5 @@ coverage>=3.6 # These are needed for docs generation oslosphinx>=2.2.0 # Apache-2.0 sphinx>=1.1.2,!=1.2.0,<1.3 + +eventlet>=0.15.1