This commit is contained in:
Edward Betts 2025-11-03 19:39:28 +00:00
parent 8a9126b729
commit 7266568010

View file

@ -3,6 +3,7 @@
import os import os
import typing import typing
from datetime import date, datetime, time, timedelta, timezone from datetime import date, datetime, time, timedelta, timezone
from time import time as unixtime
from zoneinfo import ZoneInfo from zoneinfo import ZoneInfo
from .types import StrDict from .types import StrDict
@ -113,12 +114,12 @@ async def time_function(
**kwargs: typing.Any, **kwargs: typing.Any,
) -> tuple[str, typing.Any, float, Exception | None]: ) -> tuple[str, typing.Any, float, Exception | None]:
"""Time the execution of an asynchronous function.""" """Time the execution of an asynchronous function."""
start_time, result, exception = time(), None, None start_time, result, exception = unixtime(), None, None
try: try:
result = await func(*args, **kwargs) result = await func(*args, **kwargs)
except Exception as e: except Exception as e:
exception = e exception = e
end_time = time() end_time = unixtime()
return name, result, end_time - start_time, exception return name, result, end_time - start_time, exception