From: Eric Harney Date: Fri, 3 Jan 2014 22:24:47 +0000 (-0500) Subject: Use loopingcall from openstack-common X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=a9661fba21d7e5dd3fb5d29f77266993e3adc460;p=openstack-build%2Fcinder-build.git Use loopingcall from openstack-common This removes cinder.utils.LoopingCall and uses the copy in openstack-common instead. Change-Id: Id76b89797dffcc65fbf37fd1442f221ff5bb4668 --- diff --git a/cinder/service.py b/cinder/service.py index ea21cd4eb..5e8b20b95 100644 --- a/cinder/service.py +++ b/cinder/service.py @@ -35,8 +35,8 @@ from cinder import db from cinder import exception from cinder.openstack.common import importutils from cinder.openstack.common import log as logging +from cinder.openstack.common import loopingcall from cinder.openstack.common import rpc -from cinder import utils from cinder import version from cinder import wsgi @@ -386,7 +386,7 @@ class Service(object): self.manager.init_host() if self.report_interval: - pulse = utils.LoopingCall(self.report_state) + pulse = loopingcall.LoopingCall(self.report_state) pulse.start(interval=self.report_interval, initial_delay=self.report_interval) self.timers.append(pulse) @@ -397,7 +397,7 @@ class Service(object): else: initial_delay = None - periodic = utils.LoopingCall(self.periodic_tasks) + periodic = loopingcall.LoopingCall(self.periodic_tasks) periodic.start(interval=self.periodic_interval, initial_delay=initial_delay) self.timers.append(periodic) diff --git a/cinder/utils.py b/cinder/utils.py index 90c62c6b5..707ddf5cb 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -31,8 +31,6 @@ import stat import sys import tempfile -from eventlet import event -from eventlet import greenthread from eventlet import pools from oslo.config import cfg import paramiko @@ -430,66 +428,6 @@ class LazyPluggable(object): return getattr(backend, key) -class LoopingCallDone(Exception): - """Exception to break out and stop a LoopingCall. - - The poll-function passed to LoopingCall can raise this exception to - break out of the loop normally. This is somewhat analogous to - StopIteration. - - An optional return-value can be included as the argument to the exception; - this return-value will be returned by LoopingCall.wait() - - """ - - def __init__(self, retvalue=True): - """:param retvalue: Value that LoopingCall.wait() should return.""" - self.retvalue = retvalue - - -class LoopingCall(object): - def __init__(self, f=None, *args, **kw): - self.args = args - self.kw = kw - self.f = f - self._running = False - - def start(self, interval, initial_delay=None): - self._running = True - done = event.Event() - - def _inner(): - if initial_delay: - greenthread.sleep(initial_delay) - - try: - while self._running: - self.f(*self.args, **self.kw) - if not self._running: - break - greenthread.sleep(interval) - except LoopingCallDone as e: - self.stop() - done.send(e.retvalue) - except Exception: - LOG.exception(_('in looping call')) - done.send_exception(*sys.exc_info()) - return - else: - done.send(True) - - self.done = done - - greenthread.spawn(_inner) - return self.done - - def stop(self): - self._running = False - - def wait(self): - return self.done.wait() - - class ProtectedExpatParser(expatreader.ExpatParser): """An expat parser which disables DTD's and entities by default."""