Add a signal-timeout delivery hook - #204
Open
tamird wants to merge 1 commit into
Open
Conversation
A failure raised by SIGALRM can be consumed by an event-loop callback before it reaches the test runner [1]. Existing setup and cancellation hooks require replacing the timer implementation to change how its failure is delivered. Add an item-scoped expiry hook after debugger checks and stack diagnostics. A plugin can accept the existing failure for delivery at its own execution boundary; otherwise the same exception is raised immediately. Keep timer policy and the thread method unchanged. Claiming cooperative delivery does not guarantee termination. [1]: pytest-dev#113
tamird
added a commit
to tamird/pytest-asyncio
that referenced
this pull request
Aug 20, 2026
A signal timeout can interrupt asyncio while it schedules a task's next step, leaving the task pending without a continuation [1]. Catching the resulting pytest failure and cancelling that task cannot reliably recover it. Add opt-in cooperative delivery through pytest-timeout's proposed expiry hook [2]. Queue cancellation without raising into the scheduler, then report the supplied failure at the owned runner boundary. Preserve external cancellation, process-control exceptions, and the interrupted await's traceback. Stop final runner shutdown separately when it times out; ordinary shared-runner invocations remain reusable. Keep timer selection, deadlines, debugger handling, and diagnostics in pytest-timeout. Existing signal behavior remains the default. Cooperative cancellation cannot stop blocking or cancellation-resistant code, so the thread method remains the hard process-stop option. Final runner shutdown may leave resource cleanup incomplete. Pin the producer prerequisite in a dedicated integration environment until its hook is released. Collect coverage from the isolated pytest processes and map installed-wheel paths back to the source tree. Require Coverage.py 7.10.3 for its subprocess-directory fixes [3]. [1]: pytest-dev/pytest-timeout#113 [2]: pytest-dev/pytest-timeout#204 [3]: https://coverage.readthedocs.io/en/7.10.3/changes.html
tamird
added a commit
to tamird/pytest-asyncio
that referenced
this pull request
Aug 20, 2026
A signal timeout can interrupt asyncio while it schedules a task's next step, leaving the task pending without a continuation [1]. Catching the resulting pytest failure and cancelling that task cannot reliably recover it. Add opt-in cooperative delivery through pytest-timeout's proposed expiry hook [2]. Queue cancellation without raising into the scheduler, then report the supplied failure at the owned runner boundary. Preserve external cancellation, process-control exceptions, and the interrupted await's traceback. Stop final runner shutdown separately when it times out; ordinary shared-runner invocations remain reusable. Keep timer selection, deadlines, debugger handling, and diagnostics in pytest-timeout. Existing signal behavior remains the default. Cooperative cancellation cannot stop blocking or cancellation-resistant code, so the thread method remains the hard process-stop option. Final runner shutdown may leave resource cleanup incomplete. Pin the producer prerequisite in a dedicated integration environment until its hook is released. Collect coverage from the isolated pytest processes and map installed-wheel paths back to the source tree. Require Coverage.py 7.10.3 for its subprocess-directory fixes [3]. [1]: pytest-dev/pytest-timeout#113 [2]: pytest-dev/pytest-timeout#204 [3]: https://coverage.readthedocs.io/en/7.10.3/changes.html
tamird
marked this pull request as ready for review
August 20, 2026 01:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A SIGALRM failure can be consumed by an event-loop callback before it reaches the test runner, as reported in #113. The timer hooks added in #117 allow an async plugin to replace the complete timer, but not just the delivery of its failure.
Add an item-scoped pytest_timeout_expired hook after debugger checks and stack diagnostics. A plugin can accept the existing failure for delivery at its own execution boundary; otherwise pytest-timeout raises the same exception immediately. The timer and thread method retain their existing behavior. Claiming cooperative delivery does not guarantee termination.
The paired pytest-asyncio implementation 1 uses this hook to queue cancellation without raising into asyncio's task scheduler. Its cooperative behavior is explicitly opt-in.
Prepared with Codex assistance.