This allows those who were using it to still continue using it until 2.0 where it will be removed; this makes it possible for those users to get off that code in a way that will be easily do-able (without totally breaking there code-bases, until we do that in the 2.0 release). This also removes all internal usage of that stop watch class so that the library itself will not reference it anymore. Change-Id: If313d8e7b9bdc8741db2e2e1dfb381aa3260b971
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright (C) 2014 Yahoo! Inc. All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# 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 threading
|
|
|
|
from debtcollector import moves
|
|
from oslo_utils import timeutils
|
|
|
|
|
|
# TODO(harlowja): Keep alias class... around until 2.0 is released.
|
|
StopWatch = moves.moved_class(timeutils.StopWatch, 'StopWatch', __name__,
|
|
version="1.15", removal_version="2.0")
|
|
|
|
|
|
class Timeout(object):
|
|
"""An object which represents a timeout.
|
|
|
|
This object has the ability to be interrupted before the actual timeout
|
|
is reached.
|
|
"""
|
|
def __init__(self, timeout):
|
|
if timeout < 0:
|
|
raise ValueError("Timeout must be >= 0 and not %s" % (timeout))
|
|
self._timeout = timeout
|
|
self._event = threading.Event()
|
|
|
|
def interrupt(self):
|
|
self._event.set()
|
|
|
|
def is_stopped(self):
|
|
return self._event.is_set()
|
|
|
|
def wait(self):
|
|
self._event.wait(self._timeout)
|
|
|
|
def reset(self):
|
|
self._event.clear()
|