Skip to content

Conversation

timmwagener
Copy link

@timmwagener timmwagener commented Jun 6, 2020

bpo-40894: asyncio.gather() cancelled() always False

It seems like the future subclass returned by asyncio.gather() (_GatheringFuture) can never return True for future.cancelled() even after it's cancel() has been invoked successfully (returning True) and an await on it actually raised a CancelledError. This is in contrast to the behavior of normal Futures and it seems generally to be classified as a minor bug by developers.

This PR consists of a small and simple fix. So maybe this is a minor bug, whose fix has no backward-compatibility consequences. However, my understanding is that asyncio.gather() is scheduled for deprecation, so maybe changes in this area are on halt anyways!?

Summary

This PR enables asyncio.gather().cancelled() to return True by overriding _GatheringFuture.cancelled() to return True when:

  • _GatheringFuture.done() is True.
  • _GatheringFuture has CancelledError set as exception.
  • Tests are provided.

https://bugs.python.org/issue40894

@timmwagener timmwagener requested review from 1st1 and asvetlov as code owners June 6, 2020 22:44
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@timmwagener

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@MaxwellDupre
Copy link
Contributor

Could you create a NEWS entry please? Simple one liner should suffice.

@arhadthedev
Copy link
Member

@MaxwellDupre It's unlikely, we missed him:

image

@timmwagener timmwagener force-pushed the bug/issue-40894-asyncio-gather-cancelled-always-false branch from f03e3cf to 9ed6260 Compare May 14, 2022 18:42
@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@timmwagener
Copy link
Author

timmwagener commented May 14, 2022

@MaxwellDupre @arhadthedev Rebased and added news entry. Thx for the reminder!

cjavad added a commit to SimplyPrint/printer-ws-client that referenced this pull request May 17, 2024
… connection and cancellation and handle exceptions more gracefully. This addresses the 1006 issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants