from typing import Callable, Optional
import warnings
+import exceptions
import thread_utils
logger = logging.getLogger(__name__)
# in https://code.google.com/p/verse-quiz/source/browse/trunk/timeout.py
-class TimeoutError(AssertionError):
- def __init__(self, value: str = "Timed Out"):
- self.value = value
-
- def __str__(self):
- return repr(self.value)
-
-
def _raise_exception(exception, error_message: Optional[str]):
if error_message is None:
raise exception()
def timeout(
seconds: float = 1.0,
use_signals: Optional[bool] = None,
- timeout_exception=TimeoutError,
+ timeout_exception=exceptions.TimeoutError,
error_message="Function call timed out",
):
"""Add a timeout parameter to a function and return the function.
class TimeoutError(Exception):
- pass
+ def __init__(self, value: str = "Timed out"):
+ self.value = value
+ def __str__(self):
+ return repr(self.value)