This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: asyncio.gather(..., return_exceptions=True) swallows cancellation
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, r.david.murray, socketpair, yselivanov
Priority: normal Keywords: patch

Created on 2018-01-27 05:38 by socketpair, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7209 merged yselivanov, 2018-05-29 16:52
PR 7222 merged miss-islington, 2018-05-29 21:21
PR 7224 merged yselivanov, 2018-05-29 21:44
PR 7225 merged yselivanov, 2018-05-29 21:52
PR 7231 merged miss-islington, 2018-05-29 23:22
Messages (8)
msg310843 - (view) Author: Марк Коренберг (socketpair) * Date: 2018-01-27 05:38
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.
msg310846 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2018-01-27 07:04
See also issue 26923, but I think this problem is different.
msg318059 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-05-29 16:57
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.
msg318093 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-05-29 21:20
New changeset 863b6749093a86810c4077112a857363410cc221 by Yury Selivanov in branch 'master':
bpo-32684: Fix gather to propagate cancel of itself with return_exceptions (GH-7209)
https://github.com/python/cpython/commit/863b6749093a86810c4077112a857363410cc221
msg318127 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-05-29 22:29
New changeset 036434273e6f6905403432c973d98ade1ae58197 by Yury Selivanov (Miss Islington (bot)) in branch '3.7':
bpo-32684: Fix gather to propagate cancel of itself with return_exceptions (GH-7209) (#7222)
https://github.com/python/cpython/commit/036434273e6f6905403432c973d98ade1ae58197
msg318138 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-05-29 23:20
New changeset 3b263e65a80cfcb1fc751834372533773ec024a4 by Yury Selivanov in branch '3.6':
bpo-32684: Fix gather to propagate cancel of itself with return_exceptions (GH-7224)
https://github.com/python/cpython/commit/3b263e65a80cfcb1fc751834372533773ec024a4
msg318139 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-05-29 23:20
New changeset 6f75bae74866b6acf638e3aa610d830d55b7e314 by Yury Selivanov in branch 'master':
bpo-32684: Fix nits in tests (GH-7225)
https://github.com/python/cpython/commit/6f75bae74866b6acf638e3aa610d830d55b7e314
msg318142 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-05-30 00:40
New changeset 3ddee64587482082fcbab930ff82ed67aa9f4a0d by Yury Selivanov (Miss Islington (bot)) in branch '3.7':
bpo-32684: Fix nits in tests (GH-7225) (#7231)
https://github.com/python/cpython/commit/3ddee64587482082fcbab930ff82ed67aa9f4a0d
History
Date User Action Args
2022-04-11 14:58:57adminsetgithub: 76865
2018-05-30 00:59:24yselivanovsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-05-30 00:40:59yselivanovsetmessages: + msg318142
2018-05-29 23:22:14miss-islingtonsetpull_requests: + pull_request6863
2018-05-29 23:20:28yselivanovsetmessages: + msg318139
2018-05-29 23:20:04yselivanovsetmessages: + msg318138
2018-05-29 22:29:14yselivanovsetmessages: + msg318127
2018-05-29 21:52:43yselivanovsetpull_requests: + pull_request6857
2018-05-29 21:44:43yselivanovsetpull_requests: + pull_request6856
2018-05-29 21:21:22miss-islingtonsetpull_requests: + pull_request6853
2018-05-29 21:20:11yselivanovsetmessages: + msg318093
2018-05-29 16:57:32yselivanovsetversions: - Python 3.5
2018-05-29 16:57:20yselivanovsetmessages: + msg318059
2018-05-29 16:52:43yselivanovsetkeywords: + patch
stage: patch review
pull_requests: + pull_request6844
2018-01-27 07:04:29r.david.murraysetnosy: + r.david.murray
messages: + msg310846
2018-01-27 05:38:11socketpaircreate