-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
31 lines (23 loc) · 869 Bytes
/
util.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
import asyncio
import functools
import time
from typing import Callable, Any
async def delay(delay_second: int) -> int:
print(f'sleeping for {delay_second} seconds')
await asyncio.sleep(delay_second)
print(f'finishing for {delay_second} seconds')
return delay_second
def async_timed() -> Callable:
def wrapper(func: Callable) -> Callable:
@functools.wraps(func)
async def wrapped(*args: Any, **kwargs: Any) -> Any:
print(f"starting {func.__name__} with args {args} {kwargs}")
start_time = time.time()
try:
return await func(*args, **kwargs)
finally:
end_time = time.time()
total_time = end_time - start_time
print(f"finished {func.__name__} in {total_time:.4f} seconds")
return wrapped
return wrapper