Skip to content

Commit

Permalink
add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dmyger committed Oct 23, 2024
1 parent 8c7b9e5 commit 861d983
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions test/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ timeout = 900

# Disable legacy paths.
addopts = -p no:legacypath

log_level = DEBUG
log_format = %(asctime)s [%(levelname)s] %(name)s/%(funcName)s: %(message)s
log_date_format = %Y-%m-%d %H:%M:%S.%f
11 changes: 10 additions & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,29 +648,38 @@ def __del__(self):

class Timeout(Timer):
__timeout: float
__is_running: bool

def __init__(self, name, timeout, callback, *args) -> None:
self.__timeout = timeout
self.__is_running = False
if self.is_timeout:
super().__init__(timeout, callback, *args)
self.setName(name)

@property
def is_timeout(self) -> bool:
return self.__timeout > 0
return self.__timeout is not None and self.__timeout > 0

def __enter__(self):
assert not self.__is_running, "This timer already in use"
if self.is_timeout:
self.__is_running = True
logging.getLogger(__name__).debug(
f"Start timer='{self.name}' for {self.__timeout} seconds {self.args}"
)
self.start()
return self

def __exit__(self, unused_exc_type, unused_value, unused_traceback) -> None:
_ = (unused_exc_type, unused_value, unused_traceback)
if self.is_timeout:
logging.getLogger(__name__).debug(f"Stop(1) timer='{self.name}' {self.args}")
self.cancel()

def __del__(self) -> None:
if self.is_timeout:
logging.getLogger(__name__).debug(f"Stop(2) timer='{self.name}' {self.args}")
self.cancel()


Expand Down

0 comments on commit 861d983

Please sign in to comment.