From 941e9ce497a8fdb7faed4386be5dd45faf1ff9e9 Mon Sep 17 00:00:00 2001 From: Dinis Cruz Date: Thu, 25 Jul 2024 16:43:05 +0100 Subject: [PATCH] made capture_duration to use Type_Safe base class --- .../context_managers/capture_duration.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/osbot_utils/context_managers/capture_duration.py b/osbot_utils/context_managers/capture_duration.py index fcdc232d..d0cc063e 100644 --- a/osbot_utils/context_managers/capture_duration.py +++ b/osbot_utils/context_managers/capture_duration.py @@ -1,12 +1,13 @@ +from osbot_utils.base_classes.Type_Safe import Type_Safe from osbot_utils.utils.Misc import timestamp_utc_now -class capture_duration(): - def __init__(self): - self.duration = None - self.start_timestamp = None - self.end_timestamp = None - self.seconds = None +class capture_duration(Type_Safe): + action_name : str + duration : float + start_timestamp : int + end_timestamp : int + seconds : float def __enter__(self): self.start_timestamp = timestamp_utc_now() @@ -23,7 +24,10 @@ def data(self): def print(self): print() - print(f'action took: {self.seconds} seconds') + if self.action_name: + print(f'action "{self.action_name}" took: {self.seconds} seconds') + else: + print(f'action took: {self.seconds} seconds') class print_duration(capture_duration):