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

Examine, how to properly cancel 1 task within anyio.TaskGroup #77

Closed
dolamroth opened this issue Feb 19, 2023 · 3 comments
Closed

Examine, how to properly cancel 1 task within anyio.TaskGroup #77

dolamroth opened this issue Feb 19, 2023 · 3 comments
Milestone

Comments

@dolamroth
Copy link
Collaborator

No description provided.

@dolamroth
Copy link
Collaborator Author

dolamroth commented Feb 19, 2023

May be related to:
agronholm/anyio#374
agronholm/anyio#496

From the discussion, it seems, that cancelling just one task within CancelScope may be not the desired behavior within anyio/trio paradigm.

However, since a cancellation may be delivered from non-user's code (i.e. calling library, that creates orphan tasks), such calls must be incapsulated with shielding cancel scope by user. This should be mentioned in the docs about websockets.

@dolamroth
Copy link
Collaborator Author

The task handler can actually be obtained, by calling task_group._spawn instead of task_group.start_soon, albeit not recommended.

There is also a trick with passing an inner cancel_scope outside from task: https://stackoverflow.com/a/60675826 (anyio has same API)

@dolamroth dolamroth reopened this Mar 5, 2023
@dolamroth
Copy link
Collaborator Author

In websocket endpoint, we should pass task_id from outer scope (on_release), so that user can re-define it and have possibility to call task_group.start instead of task_group.start_soon

@dolamroth dolamroth added this to the 0.1 milestone Mar 6, 2023
dolamroth referenced this issue in dolamroth/starlette-web Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant