Skip to content

concurrent.futures.Future.set_running_or_notify_cancel does not notify cancel #66820

Open

Description

@bwhmather
mannequin
BPO 22630
Nosy @brianquinlan, @pitrou
Files
  • change-callbacks.patch: Patch to change callbacks to match docs
  • 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.
  • non-magic-waiters.patch
  • 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 = None
    closed_at = None
    created_at = <Date 2014-10-14.09:05:54.451>
    labels = ['library', 'docs']
    title = '`concurrent.futures.Future.set_running_or_notify_cancel` does not notify cancel'
    updated_at = <Date 2019-05-07.16:26:55.520>
    user = 'https://bugs.python.org/bwhmather'

    bugs.python.org fields:

    activity = <Date 2019-05-07.16:26:55.520>
    actor = 'bquinlan'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2014-10-14.09:05:54.451>
    creator = 'bwhmather'
    dependencies = []
    files = ['36908', '36909', '36910', '37017']
    hgrepos = []
    issue_num = 22630
    keywords = ['patch']
    message_count = 4.0
    messages = ['229282', '230017', '303588', '341775']
    nosy_count = 4.0
    nosy_names = ['bquinlan', 'pitrou', 'docs@python', 'bwhmather']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue22630'
    versions = ['Python 3.2', 'Python 3.3', 'Python 3.4', 'Python 3.5']

    Activity

    1. bwhmather commented on Oct 14, 2014

      bwhmathermannequin
      MannequinAuthor

      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:

      1. "change-callbacks.patch" - this changes the behaviour to match the documentation.
      2. "change-docs.patch" - this fixes the documentation to match the current behaviour.
      3. "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.

    2. added
      docsDocumentation in the Doc dir
      stdlibStandard Library Python modules in the Lib/ directory
      on Oct 14, 2014
    3. bwhmather commented on Oct 25, 2014

      bwhmathermannequin
      MannequinAuthor

      Have uploaded patch to re-implement wait and as_completed using callbacks. See bpo-22729. Sorry for sitting on it for so long.

    4. pitrou commented on Oct 3, 2017

      @pitrou
      Member

      "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 :-)

    5. brianquinlan commented on May 7, 2019

      @brianquinlan
      Contributor

      Ben, do you still think that your patch is relevant or shall we close this bug?

    6. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      docsDocumentation in the Doc dirstdlibStandard Library Python modules in the Lib/ directorytopic-multiprocessing

      Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions