-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
28 lines (23 loc) · 750 Bytes
/
util.py
File metadata and controls
28 lines (23 loc) · 750 Bytes
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
import functools
import time
import logging
import asyncio
logger = logging.getLogger(__name__)
def async_timed():
def wrapper(func):
@functools.wraps(func)
async def wrapped(*args, **kwargs):
start = time.time()
try:
return await func(*args, **kwargs)
finally:
logger.info(f"{func.__name__} завершилась за {round(time.time() - start, 2)} сек")
return wrapped
return wrapper
def async_timeout(seconds):
def decorator(func):
@functools.wraps(func)
async def wrapper(*args, **kwargs):
return await asyncio.wait_for(func(*args, **kwargs), timeout=seconds)
return wrapper
return decorator