diff options
| author | Joshua Harlow <harlowja@yahoo-inc.com> | 2015-01-28 15:55:39 -0800 |
|---|---|---|
| committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2015-01-28 16:14:54 -0800 |
| commit | d5128cf51a554c2aa0f50e4b48b953933fc33f89 (patch) | |
| tree | 5d7500c5d5e164df95e30b5fb54c2ded4aa9c12e /taskflow/jobs | |
| parent | 7df57b109974f21d6201e644632873690fd661a2 (diff) | |
| download | taskflow-d5128cf51a554c2aa0f50e4b48b953933fc33f89.tar.gz | |
Stopwatch usage cleanup/tweak
Instead of optionally creating a stopwatch when a provided
timeout is not none (to avoid the stopwatch leftover() method
raising a error) just allow the stopwatch leftover() method to
not raise when no duration is provided to avoid these repeated
styles of usage/checks in the first place.
By default the leftover() method still raises an error (a new
keyword argument is now accepted to turn off this behavior).
Change-Id: If934ee6e6855adbb6975cd6ea41e273d40e73dac
Diffstat (limited to 'taskflow/jobs')
| -rw-r--r-- | taskflow/jobs/backends/impl_zookeeper.py | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/taskflow/jobs/backends/impl_zookeeper.py b/taskflow/jobs/backends/impl_zookeeper.py index 1fe7450..3e52f65 100644 --- a/taskflow/jobs/backends/impl_zookeeper.py +++ b/taskflow/jobs/backends/impl_zookeeper.py @@ -661,13 +661,12 @@ class ZookeeperJobBoard(base.NotifyingJobBoard): def wait(self, timeout=None): # Wait until timeout expires (or forever) for jobs to appear. - watch = None - if timeout is not None: - watch = tt.StopWatch(duration=float(timeout)).start() + watch = tt.StopWatch(duration=timeout) + watch.start() with self._job_cond: while True: if not self._known_jobs: - if watch is not None and watch.expired(): + if watch.expired(): raise excp.NotFound("Expired waiting for jobs to" " arrive; waited %s seconds" % watch.elapsed()) @@ -676,10 +675,7 @@ class ZookeeperJobBoard(base.NotifyingJobBoard): # when we acquire the condition that there will actually # be jobs (especially if we are spuriously awaken), so we # must recalculate the amount of time we really have left. - timeout = None - if watch is not None: - timeout = watch.leftover() - self._job_cond.wait(timeout) + self._job_cond.wait(watch.leftover(return_none=True)) else: it = ZookeeperJobBoardIterator(self) it._jobs.extend(self._fetch_jobs()) |
