Repository navigation
Conversation
…elled while pending
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
wait()andas_completed()never count a future that was cancelled while still pending as done. The documentation says wait returns the futures that "finished or were cancelled", andFuture.done()already reports such a future as done, so the two helpers contradict both the docs and the rest of the API:The root cause is that the only place waiters are notified of a cancellation is
set_running_or_notify_cancel(), which the executor calls when it eventually picks the work item off the queue. On a busy pool that can be delayed arbitrarily, so the wait never ends even though the future is already in a terminal state.The consumer-side checks in
wait(),as_completed()and_create_and_install_waiters()now treatCANCELLEDas terminal alongsideCANCELLED_AND_NOTIFIEDandFINISHED. Nothing changes on the executor side: the worker still performs the notification when it processes the item, which is a no-op for any waiter that has already been removed.Two existing tests asserted that a cancelled pending future must end up in
not_done, which contradicts the documented behaviour, so they were updated rather than preserved.test_first_completedcan now legitimately return before the first real future finishes (an already-cancelled future satisfies FIRST_COMPLETED immediately), so its assertions were relaxed to the deterministic subset instead of asserting exact sets.written with devin (the ai tool) doing most of the implementation, verified across all the executor variants myself.