GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-26552: Fixed case where failing `asyncio.ensure_future` did not close the coroutine by kumaraditya303 · Pull Request #30288 · python/cpython

Conversation

@kumaraditya303

@kumaraditya303 kumaraditya303 commented Dec 29, 2021 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

https://bugs.python.org/issue26552

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kumaraditya303
kumaraditya303 requested review from 1st1 and asvetlov as code owners December 29, 2021 13:40
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Dec 29, 2021
@bedevere-bot bedevere-bot added the awaiting review label Dec 29, 2021
@kumaraditya303 kumaraditya303 changed the title bpo-26552: fix failing ensure_future which created a Task bpo-26552: Fixed case where failing asyncio.ensure_future did not close the coroutine Dec 29, 2021
gvanrossum
gvanrossum reviewed Dec 29, 2021
View reviewed changes
Comment thread Lib/asyncio/base_events.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@carlosdmz

carlosdmz commented Dec 29, 2021 •
edited by gvanrossum
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

In Lib/asyncio/tasks.py, there's an _enclose_future()_ensure_future(), you might be able to find out whether the function has called wrap_awaitable or not. I couldn't get the edge case when there's a task with a loop closed, of which was stated on the bug report. You might be able to flag out the specific edge case and then call create_task with that flag and corner it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kumaraditya303
bpo-26552: fix failing ensure_future still creates a Task
ea3a9b4
@kumaraditya303
kumaraditya303 force-pushed the issue26552 branch from 0d0fd3f to ea3a9b4 Compare January 24, 2022 07:26
@kumaraditya303

kumaraditya303 commented Jan 24, 2022

Copy link
Copy Markdown
Contributor Author

(Rebased to main)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@arhadthedev

arhadthedev commented Jan 24, 2022

Copy link
Copy Markdown
Member

*with hope* Does it fix test_asyncio random failures on a Windows runner so it can be enabled back?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kumaraditya303
new approach
d4ecd36
@kumaraditya303
kumaraditya303 requested a review from gvanrossum January 26, 2022 11:57
@kumaraditya303

kumaraditya303 commented Jan 26, 2022

Copy link
Copy Markdown
Contributor Author

with hope Does it fix test_asyncio random failures on a Windows runner so it can be enabled back?

I fixed that issue separately.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gvanrossum
gvanrossum approved these changes Jan 28, 2022
View reviewed changes

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Kumar, I had procrastinated on reviewing this because there's some complicated stuff going on. I finally found the time and noticed that the bpo issue was written somewhat misleadingly, so I've added a clarification there.

I now finally figured out what the real issue is and how to deal with it, and your code is correct:

  • If the argument is a Future, nothing more needs to be done
  • If it is a coroutine (i.e. async def), we need to close it if create_task() raises RuntimeError (which it only does for one reason, i.e. if the event loop is closed)
  • If it is an awaitable (i.e. something with an __await__() method), it may not have a close() method; the wrapper created by _wrap_awaitable() doesn't need to be closed

So I'm going to land this now. Thanks for your patience!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303 reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Jan 28, 2022
@gvanrossum
gvanrossum merged commit 24cc641 into python:main Jan 28, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Jan 28, 2022
@bedevere-bot

bedevere-bot commented Jan 28, 2022

Copy link
Copy Markdown

@gvanrossum: Please replace # with GH- in the commit message next time. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Jan 28, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot PPC64LE CentOS9 3.x has failed when building commit 24cc641.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/852/builds/10) and take a look at the build logs.
  4. Check if the failure is related to this commit (24cc641) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/852/builds/10

Summary of the results of the build (if available):

Click to see traceback logs
remote: Enumerating objects: 13, done.        
remote: Counting objects:   9% (1/11)        
remote: Counting objects:  18% (2/11)        
remote: Counting objects:  27% (3/11)        
remote: Counting objects:  36% (4/11)        
remote: Counting objects:  45% (5/11)        
remote: Counting objects:  54% (6/11)        
remote: Counting objects:  63% (7/11)        
remote: Counting objects:  72% (8/11)        
remote: Counting objects:  81% (9/11)        
remote: Counting objects:  90% (10/11)        
remote: Counting objects: 100% (11/11)        
remote: Counting objects: 100% (11/11), done.        
remote: Total 13 (delta 11), reused 11 (delta 11), pack-reused 2        
From https://github.com/python/cpython
 * branch                  main       -> FETCH_HEAD
Note: switching to '24cc6411adbfe5555ecd8901f1ea50caa414c908'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 24cc6411ad [bpo-26552](https://bugs.python.org/issue26552): Fixed case where failing `asyncio.ensure_future` did not close the coroutine (#30288)
Switched to and reset branch 'main'

Cannot create temporary file in /tmp/: No space left on device
../Python/thread.c:257:1: fatal error: error writing to /tmp/ccTo9nrX.s: No space left on device
  257 | }
      | ^
compilation terminated.
make: *** [Makefile:2392: Python/thread.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [Makefile:2392: Python/pystrtod.o] Aborted (core dumped)
../Python/pystrcmp.c:30:1: fatal error: error writing to /tmp/ccodR3vP.s: No space left on device
   30 | }
      | ^
compilation terminated.
make: *** [Makefile:2392: Python/pystrcmp.o] Error 1
../Parser/parser.c:35925:1: fatal error: error writing to /tmp/cc3DnvC8.s: No space left on device
35925 | }
      | ^
compilation terminated.
make: *** [Makefile:2392: Parser/parser.o] Error 1
../Python/symtable.c:2188:1: fatal error: error writing to /tmp/cc0vWBNO.s: No space left on device
 2188 | }
      | ^
compilation terminated.
make: *** [Makefile:2392: Python/symtable.o] Error 1
../Python/traceback.c:1334:1: fatal error: error writing to /tmp/cc6eT91n.s: No space left on device
 1334 | }
      | ^
compilation terminated.
make: *** [Makefile:2392: Python/traceback.o] Error 1
../Python/sysmodule.c:3383:1: fatal error: error writing to /tmp/ccjLnafA.s: No space left on device
 3383 | }
      | ^
compilation terminated.
make: *** [Makefile:1373: Python/sysmodule.o] Error 1
../Objects/unicodeobject.c:16167:1: fatal error: error writing to /tmp/ccmwQWIw.s: No space left on device
16167 | }
      | ^
compilation terminated.
make: *** [Makefile:2392: Objects/unicodeobject.o] Error 1

find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
make: [Makefile:2472: clean-retain-profile] Error 1 (ignored)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kumaraditya303
kumaraditya303 deleted the issue26552 branch January 29, 2022 03:26
@kumaraditya303

kumaraditya303 commented Jan 29, 2022

Copy link
Copy Markdown
Contributor Author

@gvanrossum I think this should be backported to 3.10 and 3.9.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum

gvanrossum commented Jan 29, 2022

Copy link
Copy Markdown
Member

Yeah, makes sense. Adding the labels now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gvanrossum gvanrossum added needs backport to 3.9 labels Jan 29, 2022
@miss-islington

miss-islington commented Jan 29, 2022

Copy link
Copy Markdown
Contributor

Thanks @kumaraditya303 for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Jan 29, 2022

Copy link
Copy Markdown
Contributor

Thanks @kumaraditya303 for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington

miss-islington commented Jan 29, 2022

Copy link
Copy Markdown
Contributor

Sorry, @kumaraditya303 and @gvanrossum, I could not cleanly backport this to 3.9 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 24cc6411adbfe5555ecd8901f1ea50caa414c908 3.9

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington miss-islington assigned gvanrossum Jan 29, 2022
@miss-islington

miss-islington commented Jan 29, 2022

Copy link
Copy Markdown
Contributor

Sorry @kumaraditya303 and @gvanrossum, I had trouble checking out the 3.10 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 24cc6411adbfe5555ecd8901f1ea50caa414c908 3.10

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303 added a commit to kumaraditya303/cpython that referenced this pull request Jan 29, 2022
@kumaraditya303
bpo-26552: Fixed case where failing asyncio.ensure_future did not c…
e514f9f
…lose the coroutine (python#30288)
@kumaraditya303 kumaraditya303 mentioned this pull request Jan 29, 2022
[3.10] bpo-26552: Fixed case where failing asyncio.ensure_future did not c… …lose the coroutine #31003
Merged
@kumaraditya303

kumaraditya303 commented Jan 29, 2022

Copy link
Copy Markdown
Contributor Author

I am leaving 3.9 as it is too diverged from main.

gvanrossum reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gvanrossum pushed a commit that referenced this pull request Jan 29, 2022
@kumaraditya303
bpo-26552: Fixed case where failing asyncio.ensure_future did not c…
a5451c9
…lose the coroutine (#30288) (#31003)
@bedevere-bot

bedevere-bot commented Jan 29, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot PPC64LE CentOS9 3.10 has failed when building commit a5451c9.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/843/builds/5) and take a look at the build logs.
  4. Check if the failure is related to this commit (a5451c9) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/843/builds/5

Summary of the results of the build (if available):

Click to see traceback logs
remote: Enumerating objects: 13, done.        
remote: Counting objects:   8% (1/12)        
remote: Counting objects:  16% (2/12)        
remote: Counting objects:  25% (3/12)        
remote: Counting objects:  33% (4/12)        
remote: Counting objects:  41% (5/12)        
remote: Counting objects:  50% (6/12)        
remote: Counting objects:  58% (7/12)        
remote: Counting objects:  66% (8/12)        
remote: Counting objects:  75% (9/12)        
remote: Counting objects:  83% (10/12)        
remote: Counting objects:  91% (11/12)        
remote: Counting objects: 100% (12/12)        
remote: Counting objects: 100% (12/12), done.        
remote: Compressing objects:   9% (1/11)        
remote: Compressing objects:  18% (2/11)        
remote: Compressing objects:  27% (3/11)        
remote: Compressing objects:  36% (4/11)        
remote: Compressing objects:  45% (5/11)        
remote: Compressing objects:  54% (6/11)        
remote: Compressing objects:  63% (7/11)        
remote: Compressing objects:  72% (8/11)        
remote: Compressing objects:  81% (9/11)        
remote: Compressing objects:  90% (10/11)        
remote: Compressing objects: 100% (11/11)        
remote: Compressing objects: 100% (11/11), done.        
remote: Total 13 (delta 1), reused 11 (delta 1), pack-reused 1        
From https://github.com/python/cpython
 * branch                  3.10       -> FETCH_HEAD
Note: switching to 'a5451c96a14ac0c3ee7cef7b5c52ab1d783ec613'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at a5451c96a1 [bpo-26552](https://bugs.python.org/issue26552): Fixed case where failing `asyncio.ensure_future` did not close the coroutine (#30288) (#31003)
Switched to and reset branch '3.10'

../Modules/_io/textio.c:3338:1: fatal error: error writing to /tmp/cc6yGOcE.s: No space left on device
 3338 | };
      | ^
compilation terminated.
make: *** [Makefile:2085: Modules/textio.o] Error 1
make: *** Waiting for unfinished jobs....
../Programs/_testembed.c:1899:1: fatal error: error writing to /tmp/cclxhfYW.s: No space left on device
 1899 | }
      | ^
compilation terminated.
make: *** [Makefile:816: Programs/_testembed.o] Error 1
/tmp/ccqYhb34.s: Assembler messages:
/tmp/ccqYhb34.s: Fatal error: can't close Objects/unicodeobject.o: No space left on device
make: *** [Makefile:1855: Objects/unicodeobject.o] Error 1
../Modules/posixmodule.c:15828:1: fatal error: error writing to /tmp/ccmkQztW.s: No space left on device
15828 | }
      | ^
compilation terminated.
make: *** [Makefile:2046: Modules/posixmodule.o] Error 1

find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
find: ‘build’: No such file or directory
make: [Makefile:1928: clean-retain-profile] Error 1 (ignored)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity ZeroIntensity removed needs backport to 3.9 labels Feb 17, 2025
@kumaraditya303 kumaraditya303 added the topic-asyncio label Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gvanrossum gvanrossum gvanrossum approved these changes
@1st1 1st1 Awaiting requested review from 1st1 1st1 is a code owner
@asvetlov asvetlov Awaiting requested review from asvetlov asvetlov is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gvanrossum gvanrossum

Labels

topic-asyncio

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@kumaraditya303 @carlosdmz @arhadthedev @bedevere-bot @gvanrossum @miss-islington @the-knights-who-say-ni @ZeroIntensity
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.