-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsleep.py
34 lines (30 loc) · 864 Bytes
/
sleep.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from typing import Callable
import functools
import logging
import time
logger = logging.getLogger()
def sleep(_func: Callable =None, *, seconds: int =1) -> Callable:
"""
Sleep given amount of seconds before calling the function
Parameters
----------
_func : Callable, optional
Wrapped function (arguments allowed), by default None
seconds : int, optional
Seconds to sleep, by default 1
Returns
-------
Callable
Wrapped function
"""
def decorator_sleep_func(func):
@functools.wraps(func)
def wrapper_sleep_func(*args, **kwargs):
time.sleep(seconds)
value = func(*args, **kwargs)
return value
return wrapper_sleep_func
if _func is None:
return decorator_sleep_func
else:
return decorator_sleep_func(_func)