Skip to content

asyncio.gather(..., return_exceptions=True) swallows cancellation #76865

Closed

Description

@socketpair
BPO 32684
Nosy @bitdancer, @asvetlov, @socketpair, @1st1
PRs
  • bpo-32684: Fix gather to propagate cancel of itself with return_exceptions #7209
  • [3.7] bpo-32684: Fix gather to propagate cancel of itself with return_exceptions (GH-7209) #7222
  • [3.6] bpo-32684: Fix gather to propagate cancel of itself with return_exceptions #7224
  • bpo-32684: Fix nits in tests #7225
  • [3.7] bpo-32684: Fix nits in tests (GH-7225) #7231
  • 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 = <Date 2018-05-30.00:59:24.287>
    created_at = <Date 2018-01-27.05:38:11.141>
    labels = ['3.8', 'type-bug', '3.7', 'expert-asyncio']
    title = 'asyncio.gather(..., return_exceptions=True) swallows cancellation'
    updated_at = <Date 2018-05-30.00:59:24.286>
    user = 'https://github.com/socketpair'

    bugs.python.org fields:

    activity = <Date 2018-05-30.00:59:24.286>
    actor = 'yselivanov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-05-30.00:59:24.287>
    closer = 'yselivanov'
    components = ['asyncio']
    creation = <Date 2018-01-27.05:38:11.141>
    creator = 'socketpair'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32684
    keywords = ['patch']
    message_count = 8.0
    messages = ['310843', '310846', '318059', '318093', '318127', '318138', '318139', '318142']
    nosy_count = 4.0
    nosy_names = ['r.david.murray', 'asvetlov', 'socketpair', 'yselivanov']
    pr_nums = ['7209', '7222', '7224', '7225', '7231']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue32684'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    Activity

    1. socketpair commented on Jan 27, 2018

      socketpairmannequin
      MannequinAuthor

      Proof:

      ================

      import asyncio
      
      async def test():
          while True:
              print('sleeping 1')
              await asyncio.gather(asyncio.sleep(1), return_exceptions=True)
      
      async def amain():
          print('creating task')
          qwe = asyncio.Task(test())
          print('sleeping 2')
          await asyncio.sleep(2)
          print('cancelling task')
          qwe.cancel()
          print('waiting task for completion')
          try:
              await qwe
          except Exception as e:
              print('task complete: %r', e)
      
      loop = asyncio.get_event_loop()
      loop.run_until_complete(amain())

      ================

      This program will never complete.

      This case should be either fixed, or documented.

    2. bitdancer commented on Jan 27, 2018

      @bitdancer
      Member

      See also bpo-26923, but I think this problem is different.

    3. 1st1 commented on May 29, 2018

      @1st1
      Member

      Thanks for reporting this. Agree, this is a bug and makes it hard (if not impossible) to use gather. I've created a PR to address the issue.

    4. 1st1 commented on May 29, 2018

      @1st1
      Member

      New changeset 863b674 by Yury Selivanov in branch 'master':
      bpo-32684: Fix gather to propagate cancel of itself with return_exceptions (GH-7209)
      863b674

    5. 1st1 commented on May 29, 2018

      @1st1
      Member

      New changeset 0364342 by Yury Selivanov (Miss Islington (bot)) in branch '3.7':
      bpo-32684: Fix gather to propagate cancel of itself with return_exceptions (GH-7209) (bpo-7222)
      0364342

    6. 1st1 commented on May 29, 2018

      @1st1
      Member

      New changeset 3b263e6 by Yury Selivanov in branch '3.6':
      bpo-32684: Fix gather to propagate cancel of itself with return_exceptions (GH-7224)
      3b263e6

    7. 1st1 commented on May 29, 2018

      @1st1
      Member

      New changeset 6f75bae by Yury Selivanov in branch 'master':
      bpo-32684: Fix nits in tests (GH-7225)
      6f75bae

    8. 1st1 commented on May 30, 2018

      @1st1
      Member

      New changeset 3ddee64 by Yury Selivanov (Miss Islington (bot)) in branch '3.7':
      bpo-32684: Fix nits in tests (GH-7225) (bpo-7231)
      3ddee64

    9. 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

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions