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

Concurrency cancellation #2090

Merged
merged 1 commit into from
Dec 18, 2024
Merged

Concurrency cancellation #2090

merged 1 commit into from
Dec 18, 2024

Conversation

aron
Copy link
Contributor

@aron aron commented Dec 13, 2024

Currently a cancellation event sent to a worker with concurrency > 1 will always cancel the most recent task.

For the async _aloop we now use a weak map to track all in flight prediction tasks. On receipt of a Cancel event, we retrieve the task from the map and cancel it.

For the standard _loop method we continue to ignore the Cancel event. Relying on calling the send_cancel_signal() to terminate the worker method before sending the Cancel event. I'm not 100% clear on why the parent needs to do this but calling send_cancel_signal or raising CancelationException directly in the _loop method causes the tests to fail so I've left it as-is.

@aron aron force-pushed the concurrency-cancellation branch from 409b659 to cc8d97a Compare December 18, 2024 13:26
@aron aron requested a review from philandstuff December 18, 2024 13:27
@aron aron marked this pull request as ready for review December 18, 2024 13:27
@aron aron marked this pull request as draft December 18, 2024 13:40
@aron
Copy link
Contributor Author

aron commented Dec 18, 2024

Hmm, I've broken the sync tests somewhere, putting this back into draft while I figure it out.

Currently a cancellation event sent to a worker with `concurrency` > 1
will always cancel the most recent task.

This commit refactors the `_ChildWorker` class to exclusively send the
`Cancel` event when receiving a `CancelRequest` and then handle the
cancellation in the event loop.

For the async `_aloop` we now use a weak map to track all in flight
prediction tasks. On cancel, we retrieve the task from the map and
cancel it.

For the standard `_loop` method we send the cancellation signal to the
process as before. It's not entirely clear why the child needs to send
the signal to itself vs raising the `CancellationException` directly
but this commit leaves it as-is for simplicity.
@aron aron force-pushed the concurrency-cancellation branch from cc8d97a to d4f5e70 Compare December 18, 2024 14:54
@aron aron marked this pull request as ready for review December 18, 2024 14:54
@aron
Copy link
Contributor Author

aron commented Dec 18, 2024

I had an accidental setup=False in a WorkerConfig of the failing test... fixed now.

@aron aron merged commit 392819d into main Dec 18, 2024
19 checks passed
@aron aron deleted the concurrency-cancellation branch December 18, 2024 16:46
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

Successfully merging this pull request may close these issues.

2 participants