Nested finalisation handled differently from Trio
See original GitHub issueThank you for this excellent library. I noticed that tasks created in nested groups do not appear to be finalised when their group is cancelled. The tests below illustrate the problem. The Trio version passes.
anyio == 1.4.0 trio == 0.16.0
import pytest
import anyio
import trio
@pytest.mark.anyio
async def test_anyio():
async def subtask(finalised):
try:
await anyio.sleep(999)
finally:
# *** Not called ***
await finalised.set()
async def subgroup(finalised):
async with anyio.create_task_group() as tg:
await tg.spawn(subtask, finalised)
async def main():
finalised = anyio.create_event()
async with anyio.create_task_group() as tg:
await tg.spawn(subgroup, finalised)
await anyio.sleep(1)
await tg.cancel_scope.cancel()
assert finalised.is_set()
await main()
@pytest.mark.trio
async def test_trio():
async def subtask(finalised):
try:
await trio.sleep(999)
finally:
finalised.set()
async def subgroup(finalised):
async with trio.open_nursery() as n:
n.start_soon(subtask, finalised)
async def main():
finalised = trio.Event()
async with trio.open_nursery() as n:
n.start_soon(subgroup, finalised)
await trio.sleep(1)
n.cancel_scope.cancel()
assert finalised.is_set()
await main()
FAILED test.py::test_anyio[asyncio] - assert False
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Trio's core functionality — Trio 0.21.0+dev documentation
You can freely nest cancellation blocks, and each Cancelled exception “knows” which ... Trio is a bit different: you can't start a child...
Read more >Implement a strategy for handling (async) generator cleanup
So PEP 525 defines some hooks that trio can set, to get (a) notification that an async generator has been started, and (b)...
Read more >Structured Concurrency
The tools we use to manage complexity in single-threaded code — in particular, nested lifetimes tied to nested scopes — simply don't translate ......
Read more >pytest Documentation
expecting a successful login, and the act may need to be handled a little differently for another test class. For example, if.
Read more >American Cancer Society/American Society of Clinical ...
Approximately 40% who discontinue the drug may tolerate a different aromatase inhibitor or a different formulation of the aromatase inhibitor.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I will check this out. Your timing is pretty good because I’m currently in the middle of a major push for AnyIO v2.0 and if any semantics need to be changed, this would be the perfect opportunity for that.
Thanks, but I can wait for v2.0. I’m building a stream processing library on top of AnyIO, still in the early stages of development.