-
-
Notifications
You must be signed in to change notification settings - Fork 388
Disallow absolute deadlines for relative cancel scopes #3403
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
A5rocks
wants to merge
1
commit into
python-trio:main
Choose a base branch
from
A5rocks:remove-deprecation
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.
+18
−27
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Trying to use absolute deadlines on a `trio.CancelScope` constructed | ||
| with a relative deadline now raises, after being deprecated since Trio | ||
| 0.27.0. | ||
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -246,26 +246,22 @@ async def test_timeout_deadline_on_entry(mock_clock: _core.MockClock) -> None: | |||||||||
| async def test_invalid_access_unentered(mock_clock: _core.MockClock) -> None: | ||||||||||
| cs = move_on_after(5) | ||||||||||
| mock_clock.jump(3) | ||||||||||
| start = _core.current_time() | ||||||||||
|
|
||||||||||
| match_str = "^unentered relative cancel scope does not have an absolute deadline" | ||||||||||
| with pytest.warns(DeprecationWarning, match=match_str): | ||||||||||
| assert cs.deadline == start + 5 | ||||||||||
| mock_clock.jump(1) | ||||||||||
| # this is hella sketchy, but they *have* been warned | ||||||||||
| with pytest.warns(DeprecationWarning, match=match_str): | ||||||||||
| assert cs.deadline == start + 6 | ||||||||||
| match_str = "^Unentered relative cancel scope does not have an absolute deadline" | ||||||||||
| with pytest.raises(RuntimeError, match=match_str): | ||||||||||
| print("SHOULD NOT PRINT! deadline:", cs.deadline) | ||||||||||
|
Comment on lines
+251
to
+252
Member
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.
Suggested change
no need for the print, no? |
||||||||||
|
|
||||||||||
| with pytest.warns(DeprecationWarning, match=match_str): | ||||||||||
| with pytest.raises(RuntimeError, match=match_str): | ||||||||||
| cs.deadline = 7 | ||||||||||
| # now transformed into absolute | ||||||||||
| assert cs.deadline == 7 | ||||||||||
| assert not cs.is_relative | ||||||||||
|
|
||||||||||
| # nothing happened! | ||||||||||
| assert cs.relative_deadline == 5 | ||||||||||
| assert cs.is_relative | ||||||||||
|
|
||||||||||
| cs = move_on_at(5) | ||||||||||
|
|
||||||||||
| match_str = ( | ||||||||||
| "^unentered non-relative cancel scope does not have a relative deadline$" | ||||||||||
| "^Unentered non-relative cancel scope does not have a relative deadline$" | ||||||||||
| ) | ||||||||||
| with pytest.raises(RuntimeError, match=match_str): | ||||||||||
| assert cs.relative_deadline | ||||||||||
|
|
||||||||||
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.
Maybe have a small snippet about how to port old code if this wasn't already mentioned in 0.27.0's release notes, though I wouldn't expect many people to encounter that since it's been depreciated for quite a bit now.
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.
The correct solution is to create a new
CancelScope, or calculate what the relative time would be with the help oftrio.current_time(), or often simply just simplifying code that previously needlessly set absolute deadlines withcs.deadline = trio.current_time() + 5.But I think the resolutions are varied and simple enough that it's not worth trying to cater too much to it.