From c529ae20940429e9ee98d6199e4e9d42e85ab7b6 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Wed, 10 Jan 2024 22:41:30 -0500 Subject: [PATCH] fix: display timeout calling context (#27) --- eth_retry/eth_retry.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/eth_retry/eth_retry.py b/eth_retry/eth_retry.py index 8fd15a5..e886164 100644 --- a/eth_retry/eth_retry.py +++ b/eth_retry/eth_retry.py @@ -156,9 +156,13 @@ def should_retry(e: Exception, failures: int) -> bool: return False - +_aio_files = [ + "asyncio/events.py" + "asyncio/base_events.py" +] def _get_caller_details_from_stack() -> str: - code_context = inspect.stack()[2].code_context - if code_context is None: - return f"{inspect.stack()[2].filename} line {inspect.stack()[2].lineno}" - return f"{inspect.stack()[2].filename} line {inspect.stack()[2].lineno} {[code_context[0].strip()]}" + for frame in inspect.stack()[2:]: + if all(filename not in frame.filename for filename in _aio_files): + details = f"{frame.filename} line {frame.lineno}" + context = frame.code_context + return details if context is None else f"{details} {[context[0].strip()]}"