Files
deb-python-taskflow/taskflow/types/timing.py
Joshua Harlow 543cf78a6f Remove 2.6 classifier + 2.6 compatibility code
Fixes bug 1445827

Depends-On: I02e3c9aacef0b295a2f823a5cbaf11768a90cb82

Change-Id: I1db681803598ac1bc917fd74a99458bc61edf3f1
2015-06-21 09:39:12 -07:00

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 oslo_utils import timeutils
#: Moved to oslo.utils (just reference them from there until a later time).
Split = timeutils.Split
#: Moved to oslo.utils (just reference them from there until a later time).
StopWatch = timeutils.StopWatch
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()