From 9604fc9c4379a78c0a7ee6bc18a6bda2b9baa052 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 17 Mar 2016 09:46:12 -0700 Subject: [PATCH] Use a timeutils.StopWatch for cancel timing Instead of using time.time and such directly the oslo utils timeutils code provides a handy timer that itself uses monotonic time (so it won't be affected by time shifts) so prefer to use that for the timer like code that exists in this new cancel code. Change-Id: Ie41f8e90cf1cb3f62fd0def00b0bc7068acd2c40 --- oslo_service/threadgroup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/oslo_service/threadgroup.py b/oslo_service/threadgroup.py index f700207a..2f947ef8 100644 --- a/oslo_service/threadgroup.py +++ b/oslo_service/threadgroup.py @@ -11,16 +11,16 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. + import logging import threading -import time import eventlet from eventlet import greenpool from oslo_service._i18n import _LE from oslo_service import loopingcall - +from oslo_utils import timeutils LOG = logging.getLogger(__name__) @@ -178,10 +178,10 @@ class ThreadGroup(object): if timeout is None: return wait_time = kwargs.get('wait_time', 1) - start = time.time() + watch = timeutils.StopWatch(duration=timeout) + watch.start() while self._any_threads_alive(): - run_time = time.time() - start - if run_time < timeout: + if not watch.expired(): eventlet.sleep(wait_time) continue LOG.debug("Cancel timeout reached, stopping threads.")