update
This commit is contained in:
parent
4f8b67a794
commit
37b8bd60a1
@ -1,4 +1,6 @@
|
||||
from collections.abc import Hashable
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
from rich.console import Console
|
||||
|
||||
@ -6,23 +8,22 @@ console = Console()
|
||||
|
||||
timers_started_ats = dict()
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def start_timer(name=1, do_print=True):
|
||||
|
||||
def start_timer(name: Hashable = 1, do_print=True):
|
||||
started_at = datetime.now()
|
||||
timers_started_ats[name] = started_at
|
||||
if do_print:
|
||||
console.print(f"{name:<{len(str(name)) + 4}} ", end="")
|
||||
print(f"started at: {started_at.strftime('%H:%M:%S.%f')}")
|
||||
log.info("%s_started", name)
|
||||
return name, started_at
|
||||
|
||||
|
||||
def stop_timer(name=1, do_print=True):
|
||||
def stop_timer(name: Hashable = 1, do_print=True):
|
||||
ended_at = datetime.now()
|
||||
took = ended_at - timers_started_ats[name]
|
||||
if do_print:
|
||||
console.print(f"{name:<{len(str(name)) + 4}} ", end="")
|
||||
print(f"{'ended at:':>11} {ended_at.strftime('%H:%M:%S.%f')} ", end="")
|
||||
console.print(f"took: {took}")
|
||||
log.info("%s_ended took=%s", name, took.total_seconds())
|
||||
return name, ended_at, took
|
||||
|
||||
|
||||
@ -32,4 +33,3 @@ if __name__ == "__main__":
|
||||
start_timer()
|
||||
sleep(1)
|
||||
stop_timer()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user