question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested finalisation handled differently from Trio

See original GitHub issue

Thank 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:closed
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
agronholmcommented, Jul 15, 2020

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.

0reactions
mjwestcottcommented, Jul 15, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found