Skip to content
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

Cancelling TaskGroup.start() cancels TaskGroup itself (only for asyncio backend) #710

Open
2 tasks done
jonathanslenders opened this issue Apr 2, 2024 · 4 comments · May be fixed by #717
Open
2 tasks done

Cancelling TaskGroup.start() cancels TaskGroup itself (only for asyncio backend) #710

jonathanslenders opened this issue Apr 2, 2024 · 4 comments · May be fixed by #717
Labels
bug Something isn't working

Comments

@jonathanslenders
Copy link
Contributor

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

AnyIO version

4.3.0

Python version

3.11.6

What happened?

Consider this snippet:

from anyio import create_task_group, run, sleep_forever, move_on_after


async def in_task_group(task_status):
    await sleep_forever()


async def main():
    async with create_task_group() as tg:
        with move_on_after(1):
            await tg.start(in_task_group)

        print(tg.cancel_scope.cancel_called). # prints 'True'


run(main, backend='asyncio')

Here we spawn a task using TaskGroup.start() then we cancel the .start() call using move_on_after. It turns out this cancels the task group as a whole.

I'd expect this to cancel only that particular task.

For the trio backend, this works fine, and does not cancel the task group.

How can we reproduce the bug?

(see snippet above)

@jonathanslenders jonathanslenders added the bug Something isn't working label Apr 2, 2024
@agronholm
Copy link
Owner

Isn't this a duplicate of #685?

@jonathanslenders
Copy link
Contributor Author

It might be, I don't really understand whether or not it's exactly the same.

@agronholm
Copy link
Owner

I think it probably at least stems from the same issue which I intend to fix for the next release.

@jonathanslenders
Copy link
Contributor Author

Thanks! That would be awesome. Feel free to close this or copy over the snippet as an additional test case if you prefer that.

agronholm added a commit that referenced this issue Apr 14, 2024
This change fixes the problem by special casing the situation where the Future backing `task_status` was cancelled which only happens when the host task is cancelled.

Fixes #685. Fixes #710.
agronholm added a commit that referenced this issue Apr 14, 2024
This change fixes the problem by special casing the situation where the Future backing `task_status` was cancelled which only happens when the host task is cancelled.

Fixes #685. Fixes #710.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants