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
This commit is contained in:
parent
8483811889
commit
394fbf4f04
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user