Add docstrings and imports
This commit is contained in:
parent
b778c644c3
commit
036c1dfa6f
@ -9,7 +9,7 @@
|
||||
__version__ = '4.0.0'
|
||||
__version_tuple__ = (4, 0, 0)
|
||||
|
||||
__all__ = ('func_timeout', 'set_timeout', 'FunctionTimedOut')
|
||||
__all__ = ('func_timeout', 'set_timeout', 'set_modifiable_timeout', 'FunctionTimedOut')
|
||||
|
||||
from .exceptions import FunctionTimedOut
|
||||
from .dafunc import func_timeout, set_timeout
|
||||
from .dafunc import func_timeout, set_timeout, set_modifiable_timeout
|
||||
|
||||
@ -14,6 +14,16 @@ __all__ = ('set_timeout', 'func_timeout')
|
||||
|
||||
|
||||
def set_timeout(timeout):
|
||||
'''
|
||||
set_timeout - Wrapper to run a function with a given timeout (max execution time)
|
||||
|
||||
@param timeout <float> - Number of seconds max to allow function to execute
|
||||
|
||||
@throws FunctionTimedOut If time alloted passes without function returning naturally
|
||||
|
||||
@see func_timeout
|
||||
@see set_modifiable_timeout
|
||||
'''
|
||||
def _function_decorator(func):
|
||||
def _function_wrapper(*args, **kwargs):
|
||||
return func_timeout(timeout, func, args=args, kwargs=kwargs)
|
||||
@ -21,6 +31,29 @@ def set_timeout(timeout):
|
||||
|
||||
return _function_decorator
|
||||
|
||||
def set_modifiable_timeout(timeout):
|
||||
'''
|
||||
set_modifiable_timeout - Wrapper to run a function with a given timeout (max execution time)
|
||||
which can be overriden by passing "forceTimeout" to the function being decorated
|
||||
|
||||
@param timeout <float> - Default Number of seconds max to allow function to execute
|
||||
|
||||
@throws FunctionTimedOut If time alloted passes without function returning naturally
|
||||
|
||||
@see func_timeout
|
||||
@see set_timeout
|
||||
'''
|
||||
def _function_decorator(func):
|
||||
def _function_wrapper(*args, **kwargs):
|
||||
if 'forceTimeout' in kwargs:
|
||||
useTimeout = kwargs.pop('forceTimeout')
|
||||
else:
|
||||
useTimeout = timeout
|
||||
|
||||
return func_timeout(useTimeout, func, args=args, kwargs=kwargs)
|
||||
return _function_wrapper
|
||||
return _function_decorator
|
||||
|
||||
def func_timeout(timeout, func, args=(), kwargs=None):
|
||||
'''
|
||||
func_timeout - Runs the given function for up to #timeout# seconds.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user