Skip to content

Commit 55ceaa6

Browse files
committed
timeouts: don't cancel on timeout during a debugging session
Fixes #16
1 parent fda12d3 commit 55ceaa6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ generator fixtures.
2121
Changelog
2222
---------
2323

24+
0.7.2 - TBD
25+
* Timeouts don't take affect if the debugger is active
26+
2427
0.7.1 - 23 June 2023
2528
* No functional changes, only fixing how hatchling understands the
2629
license field in the pyproject.toml with thanks to @piotrm-nvidia
@@ -159,6 +162,10 @@ The default timeout is 5 seconds. You can change this default by setting the
159162
This setting is also available from the CLI using the ``--default-async-timeout``
160163
option.
161164

165+
Note that if the timeout fires whilst you have the debugger active then the timeout
166+
will not cancel the current test. This is determined by checking if ``sys.gettrace()``
167+
returns a non-None value.
168+
162169
Overriding the loop
163170
-------------------
164171

alt_pytest_asyncio/async_converters.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,13 @@ async def async_runner(func, timeout, info, args, kwargs):
233233

234234
def timeout_task(task):
235235
if not task.done():
236-
info["cancelled"] = True
237-
task.cancel()
236+
# If the debugger is active then don't cancel, so that debugging may continue
237+
# sys.gettrace is not a language feature and notguaranteed to be available
238+
# on all python implementations, so we see if it exists
239+
gettrace = getattr(sys, "gettrace", None)
240+
if gettrace is None or gettrace() is None:
241+
info["cancelled"] = True
242+
task.cancel()
238243

239244
asyncio.get_event_loop().call_later(timeout, timeout_task, current_task)
240245

0 commit comments

Comments
 (0)