Repository navigation
New trio.lowlevel.hold_autojump() context manager, and use in to_thread.run_sync()
#3553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Zac-HD
wants to merge
6
commits into
python-trio:main
Choose a base branch
from
Zac-HD:claude/peaceful-volta-r6wj0f
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f85c964
Make the autojump clock wait for to_thread.run_sync threads
claude 33ba976
Add trio.lowlevel.hold_autojump
claude 0cecf9b
Build to_thread's autojump hold on trio.lowlevel.hold_autojump
claude 134196b
Make hold_autojump a public keyword of to_thread.run_sync
claude f3044ab
Assert that hold_autojump() blocks exit normally in their own run
claude 15d1e93
Trim the autojump newsfragments and MockClock docs
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Added `trio.lowlevel.hold_autojump`, a context manager that keeps the | ||
| autojump clock (`trio.testing.MockClock` with a finite | ||
| ``autojump_threshold``) from jumping while the block runs. It is for code | ||
| that parks a task with `trio.lowlevel.wait_task_rescheduled` until work | ||
| outside the run loop finishes -- in a thread, or on another event loop -- | ||
| and wakes it through `trio.lowlevel.TrioToken.run_sync_soon`. Such a task | ||
| otherwise looks idle, so virtual time could jump past its timeouts while the | ||
| work is still in progress. `trio.to_thread.run_sync` gained a matching | ||
| ``hold_autojump`` argument. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| The autojump clock (`trio.testing.MockClock` with a finite | ||
| ``autojump_threshold``) no longer jumps virtual time ahead while a task is | ||
| waiting for a thread started by `trio.to_thread.run_sync`, which made timeouts | ||
| in concurrent tasks fire spuriously. A thread that waits until a task has | ||
| slept in virtual time (for example on a `queue.Queue` that a task fills after | ||
| a `trio.sleep`) must now be started with ``hold_autojump=False``, or it | ||
| deadlocks. |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,10 @@ async def _waitid_system_task(pid: int, event: Event) -> None: | |
| pid, | ||
| abandon_on_cancel=True, | ||
| limiter=waitid_limiter, | ||
| # This thread only waits for the child to exit. Where the platform | ||
| # allows, that is an I/O wait, which does not hold the autojump | ||
| # clock either. | ||
| hold_autojump=False, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this implied by |
||
| ) | ||
| except OSError: | ||
| # If waitid fails, waitpid will fail too, so it still makes | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it may be worth adding a
assert runner == GLOBAL_RUN_CONTEXT.runnerat the end? Or in thefinally?