Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-117536: Fix asyncio _asyncgen_finalizer_hook()#117751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commentedApr 11, 2024
edited by bedevere-appbot
Loading

Make the finalization of asynchronous generators more reliable.

Store a strong reference to the asynchronous generator which is being closed to make sure that shutdown_asyncgens() can close it even if asyncio.run() cancels all tasks.

Make the finalization of asynchronous generators more reliable.Store a strong reference to the asynchronous generator which is beingclosed to make sure that shutdown_asyncgens() can close it even ifasyncio.run() cancels all tasks.
@vstinner
Copy link
MemberAuthor

I'm not sure of my fix, I didn't touch asyncio for a long time.

I don't know if_asyncgen_close() works as expected, in my quick local tests, I never saw the task executed and I don't know why. It's always shutdown_asyncgens() which closed the async generator for me.

The subtle part is inrunner.py:

_cancel_all_tasks(loop)loop.run_until_complete(loop.shutdown_asyncgens())loop.run_until_complete(loop.shutdown_default_executor(constants.THREAD_JOIN_TIMEOUT))

First, all tasks are cancelled, including_asyncgen_close(agen) task.

@vstinner
Copy link
MemberAuthor

@kumaraditya303: Would you mind to have a look at this asyncio change?

yield0
yield1
finally:
ns['state']='finalized'
Copy link
Contributor

Choose a reason for hiding this comment

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

This should await something to prove it's getting aclosed properly

Suggested change
ns['state']='finalized'
awaitasyncio.sleep(0)
ns['state']='finalized'

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Right. I added a second test. I prefer to have two tests, since having 'await' also changes the behavior in a subtle way.

raiseRuntimeError('Executor shutdown has been called')

asyncdef_asyncgen_close(self,agen):
awaitagen.aclose()
Copy link
Contributor

Choose a reason for hiding this comment

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

this is just side-stepping the actual bug by delaying the creation of the async_generator_aclose object to avoid the incorrect warning

@graingert
Copy link
Contributor

sorry I accidentally closed this PR

@vstinner
Copy link
MemberAuthor

I'm sorry, I don't understand this code enough to address reviews. I prefer to abandon my PR.

If someone wants to take it over, please go ahead :-)

@vstinnervstinner deleted the asyncio_shutdown_asyncgens branchApril 15, 2024 20:00
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@graingertgraingertgraingert requested changes

@1st11st1Awaiting requested review from 1st11st1 is a code owner

@asvetlovasvetlovAwaiting requested review from asvetlovasvetlov is a code owner

@gvanrossumgvanrossumAwaiting requested review from gvanrossum

@kumaraditya303kumaraditya303Awaiting requested review from kumaraditya303kumaraditya303 is a code owner

@willingcwillingcAwaiting requested review from willingcwillingc is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@vstinner@graingert

[8]ページ先頭

©2009-2025 Movatter.jp