Python library timerx records timing data even when timed code raises exceptions
A developer has released timerx, a small dependency-free Python timing utility designed to fix a common flaw in ad-hoc timing code. Standard Python timing patterns silently drop measurements when the timed function raises an exception, meaning the slowest or most problematic calls go unrecorded. timerx solves this by wrapping all three entry points — decorator, context manager, and named stopwatch — with finally blocks that guarantee timing is recorded regardless of whether an exception occurs. The library also handles re-entrant or recursive timing under the same name by storing start times as a stack rather than a single slot, preventing silent overwrites. Exceptions are never suppressed; the library only observes and records, leaving error handling entirely to the caller's code.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in