diff options
author | Kei Masumoto <masumotok@nttdata.co.jp> | 2011-01-19 08:50:47 +0900 |
---|---|---|
committer | Kei Masumoto <masumotok@nttdata.co.jp> | 2011-01-19 08:50:47 +0900 |
commit | 8c92638f89029e34717558e56aa1202958085d22 (patch) | |
tree | 128b1e0629cb8796abf47a02862ed8f8169e03a7 /nova/utils.py | |
parent | a0779f5df2829f91bdc944e7275f44bd831643cc (diff) | |
parent | 8e6684a58eea3ecacdde99e1940d2ae351b8465c (diff) | |
download | nova-8c92638f89029e34717558e56aa1202958085d22.tar.gz nova-8c92638f89029e34717558e56aa1202958085d22.tar.xz nova-8c92638f89029e34717558e56aa1202958085d22.zip |
merged to trunk rev572
Diffstat (limited to 'nova/utils.py')
-rw-r--r-- | nova/utils.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/nova/utils.py b/nova/utils.py index fdbe81c0c..6d3ddd092 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -334,6 +334,20 @@ class LazyPluggable(object): return getattr(backend, key) +class LoopingCallDone(Exception): + """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 @@ -352,12 +366,15 @@ class LoopingCall(object): while self._running: self.f(*self.args, **self.kw) greenthread.sleep(interval) + except LoopingCallDone, e: + self.stop() + done.send(e.retvalue) except Exception: logging.exception('in looping call') done.send_exception(*sys.exc_info()) return - - done.send(True) + else: + done.send(True) self.done = done |