You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
concurrent.futures.Future.set_running_or_notify_cancel does not notify cancel #66820
change-docs.patch: Fixes the documentation to match the current behaviour.
change-docs-and-waiters.patch: in addition to fixing the documentation, this also fixes the inconsistency between waiters and callbacks by invoking waiters' add_cancelled method in cancel.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2014-10-14.09:05:54.451>labels= ['library', 'docs']
title='`concurrent.futures.Future.set_running_or_notify_cancel` does not notify cancel'updated_at=<Date2019-05-07.16:26:55.520>user='https://bugs.python.org/bwhmather'
The documentation for the set_running_or_notify_cancel method on concurrent.futures.Future states that it will notify waiting threads and trigger callbacks after the Future has been cancelled, however currently this is done immediately by the call to cancel.
Oddly waiters (private interface used to implement wait and as_completed) do follow the behaviour documented for callbacks (they are called in set_running_or_notify_cancel) which means that they are not equivalent to setting a callback on each future.
I have attached three possible patches:
"change-callbacks.patch" - this changes the behaviour to match the documentation.
"change-docs.patch" - this fixes the documentation to match the current behaviour.
"change-docs-and-waiters.patch" - in addition to fixing the documentation, this also fixes the inconsistency between waiters and callbacks by invoking waiters' add_cancelled method in cancel.
I believe moving to the documented behaviour (1) would be a mistake as currently set_running_or_notify_cancel and the RUNNING state can be skipped entirely allowing Futures to be used just as a way to send results.
Should mention that I have a separate patch (which I will submit separately (or here?)) that re-implements wait and as_completed using only publicly exposed methods. This makes it possible to extend or replace Future without having to preserve its private interface. Unfortunately this slightly breaks compatibility due to the difference between waiters and callbacks. I thought it would be best to discuss this issue first as I don't believe the current behaviour is as intended.
Activity
bwhmather commentedon Oct 14, 2014
The documentation for the
set_running_or_notify_cancelmethod onconcurrent.futures.Futurestates that it will notify waiting threads and trigger callbacks after theFuturehas been cancelled, however currently this is done immediately by the call tocancel.Oddly waiters (private interface used to implement
waitandas_completed) do follow the behaviour documented for callbacks (they are called inset_running_or_notify_cancel) which means that they are not equivalent to setting a callback on each future.I have attached three possible patches:
add_cancelledmethod incancel.I believe moving to the documented behaviour (1) would be a mistake as currently
set_running_or_notify_canceland theRUNNINGstate can be skipped entirely allowing Futures to be used just as a way to send results.Should mention that I have a separate patch (which I will submit separately (or here?)) that re-implements
waitandas_completedusing only publicly exposed methods. This makes it possible to extend or replaceFuturewithout having to preserve its private interface. Unfortunately this slightly breaks compatibility due to the difference between waiters and callbacks. I thought it would be best to discuss this issue first as I don't believe the current behaviour is as intended.bwhmather commentedon Oct 25, 2014
Have uploaded patch to re-implement
waitandas_completedusing callbacks. See bpo-22729. Sorry for sitting on it for so long.pitrou commentedon Oct 3, 2017
"change-docs-and-waiters.patch" looks reasonable on the principle, but I doubt it still applies.
Also, we use Github nowadays. You may still upload patches if you prefer, but pull requests have become the recommended way to submit changes :-)
brianquinlan commentedon May 7, 2019
Ben, do you still think that your patch is relevant or shall we close this bug?