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