-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
ASYNC100 now treats start_soon() as a cancel point #327
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 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,26 @@ | ||
# AUTOFIX | ||
# BASE_LIBRARY anyio | ||
# NOTRIO # trio.create_task_group doesn't exist | ||
# ASYNCIO_NO_ERROR | ||
import anyio | ||
|
||
|
||
async def bar() -> None: ... | ||
|
||
|
||
async def anyio_cancelscope(): | ||
# error: 9, "anyio", "CancelScope" | ||
... | ||
|
||
|
||
# see async100_trio for more comprehensive tests | ||
async def nursery_no_cancel_point(): | ||
# error: 9, "anyio", "CancelScope" | ||
async with anyio.create_task_group(): | ||
... | ||
|
||
|
||
async def nursery_with_start_soon(): | ||
with anyio.CancelScope(): | ||
async with anyio.create_task_group() as tg: | ||
tg.start_soon(bar) |
This file contains 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,23 @@ | ||
--- | ||
+++ | ||
@@ x,15 x,15 @@ | ||
|
||
|
||
async def anyio_cancelscope(): | ||
- with anyio.CancelScope(): # error: 9, "anyio", "CancelScope" | ||
- ... | ||
+ # error: 9, "anyio", "CancelScope" | ||
+ ... | ||
|
||
|
||
# see async100_trio for more comprehensive tests | ||
async def nursery_no_cancel_point(): | ||
- with anyio.CancelScope(): # error: 9, "anyio", "CancelScope" | ||
- async with anyio.create_task_group(): | ||
- ... | ||
+ # error: 9, "anyio", "CancelScope" | ||
+ async with anyio.create_task_group(): | ||
+ ... | ||
|
||
|
||
async def nursery_with_start_soon(): |
This file contains 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 |
---|---|---|
@@ -1,10 +1,51 @@ | ||
# AUTOFIX | ||
# ASYNCIO_NO_ERROR # asyncio.open_nursery doesn't exist | ||
# ANYIO_NO_ERROR # anyio.open_nursery doesn't exist | ||
# NOANYIO # anyio.open_nursery doesn't exist | ||
import trio | ||
|
||
|
||
async def nursery_no_cancel_point(): | ||
with trio.CancelScope(): # should error, but reverted PR | ||
async with trio.open_nursery(): | ||
... | ||
# error: 9, "trio", "CancelScope" | ||
async with trio.open_nursery(): | ||
... | ||
|
||
|
||
# but it is a cancel point if the nursery contains a call to start_soon() | ||
|
||
|
||
async def nursery_start_soon(): | ||
with trio.CancelScope(): | ||
async with trio.open_nursery() as n: | ||
n.start_soon(trio.sleep, 0) | ||
|
||
|
||
async def nursery_start_soon_misnested(): | ||
async with trio.open_nursery() as n: | ||
with trio.CancelScope(): | ||
n.start_soon(trio.sleep, 0) | ||
|
||
|
||
async def nested_scope(): | ||
with trio.CancelScope(): | ||
with trio.CancelScope(): | ||
async with trio.open_nursery() as n: | ||
n.start_soon(trio.sleep, 0) | ||
|
||
|
||
async def nested_nursery(): | ||
with trio.CancelScope(): | ||
async with trio.open_nursery() as n: | ||
async with trio.open_nursery() as n2: | ||
n2.start_soon(trio.sleep, 0) | ||
|
||
|
||
async def nested_function_call(): | ||
|
||
# error: 9, "trio", "CancelScope" | ||
async with trio.open_nursery() as n: | ||
|
||
def foo(): | ||
n.start_soon(trio.sleep, 0) | ||
|
||
# a false alarm in case we call foo()... but we can't check if they do | ||
foo() |
This file contains 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,33 @@ | ||
--- | ||
+++ | ||
@@ x,9 x,9 @@ | ||
|
||
|
||
async def nursery_no_cancel_point(): | ||
- with trio.CancelScope(): # error: 9, "trio", "CancelScope" | ||
- async with trio.open_nursery(): | ||
- ... | ||
+ # error: 9, "trio", "CancelScope" | ||
+ async with trio.open_nursery(): | ||
+ ... | ||
|
||
|
||
# but it is a cancel point if the nursery contains a call to start_soon() | ||
@@ x,11 x,11 @@ | ||
|
||
async def nested_function_call(): | ||
|
||
- with trio.CancelScope(): # error: 9, "trio", "CancelScope" | ||
- async with trio.open_nursery() as n: | ||
+ # error: 9, "trio", "CancelScope" | ||
+ async with trio.open_nursery() as n: | ||
|
||
- def foo(): | ||
- n.start_soon(trio.sleep, 0) | ||
+ def foo(): | ||
+ n.start_soon(trio.sleep, 0) | ||
|
||
- # a false alarm in case we call foo()... but we can't check if they do | ||
- foo() | ||
+ # a false alarm in case we call foo()... but we can't check if they do | ||
+ foo() |
This file contains 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 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,26 @@ | ||
# AUTOFIX | ||
# BASE_LIBRARY anyio | ||
# NOTRIO # trio.create_task_group doesn't exist | ||
# ASYNCIO_NO_ERROR | ||
import anyio | ||
|
||
|
||
async def bar() -> None: ... | ||
|
||
|
||
async def anyio_cancelscope(): | ||
with anyio.CancelScope(): # error: 9, "anyio", "CancelScope" | ||
... | ||
|
||
|
||
# see async100_trio for more comprehensive tests | ||
async def nursery_no_cancel_point(): | ||
with anyio.CancelScope(): # error: 9, "anyio", "CancelScope" | ||
async with anyio.create_task_group(): | ||
... | ||
|
||
|
||
async def nursery_with_start_soon(): | ||
with anyio.CancelScope(): | ||
async with anyio.create_task_group() as tg: | ||
tg.start_soon(bar) |
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 don't think this is quite correct;
.start_soon(...)
is not itself a cancel point, but rather it means thatNursery.__aexit__
will be a cancel point.(unless there is an earlier checkpoint in the nursery block, during which the task finishes - in which case we can rely on that checkpoint instead)
It's a pretty subtle distinction but we should be careful about that in both implementation and docs.
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.
Ah good catch, I thought it wouldn't make a difference to the implementation at first but turns out it does. Fixed~