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-140287: HandlePYTHONSTARTUP script exceptions in the asyncio REPL#140288

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

Open
johnslavik wants to merge34 commits intopython:main
base:main
Choose a base branch
Loading
fromjohnslavik:asyncio-repl-handle-python-startup

Conversation

@johnslavik
Copy link
Contributor

@johnslavikjohnslavik commentedOct 18, 2025
edited by bedevere-appbot
Loading

This is generally a work in progress; tests are needed.
The asyncio patch is simple and ready.

@johnslavik
Copy link
ContributorAuthor

Please merge#140298 first.

@johnslavikjohnslavik marked this pull request as ready for reviewOctober 23, 2025 14:57
@johnslavikjohnslavik marked this pull request as draftOctober 23, 2025 15:00
# Isolated mode implies -E, -P and -s, purifies sys.path and ignores PYTHON*
# variables.
ifisolated:
cmd_line.append('-I')
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

To reuse this routine andspawn_asyncio_repl below, we need to have a knob to not pass-I since that ignoresPYTHONSTARTUP completely.

The asyncio REPL currently doesn't comply to that, which is a separate issue I'll report having learnt this.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Tracking the-I edge case in#140648.

Comment on lines -295 to -311
deftest_asyncio_repl_reaches_python_startup_script(self):
withos_helper.temp_dir()astmpdir:
script=os.path.join(tmpdir,"pythonstartup.py")
withopen(script,"w")asf:
f.write("print('pythonstartup done!')"+os.linesep)
f.write("exit(0)"+os.linesep)

env=os.environ.copy()
env["PYTHON_HISTORY"]=os.path.join(tmpdir,".asyncio_history")
env["PYTHONSTARTUP"]=script
subprocess.check_call(
[sys.executable,"-m","asyncio"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env,
timeout=SHORT_TIMEOUT,
)
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Covered byTestPythonStartup now, so not needed here.

@johnslavik
Copy link
ContributorAuthor

johnslavik commentedNov 8, 2025
edited
Loading

It seems that the asyncio REPL on Windows leaks the event loop:

❯ PYTHONSTARTUP='' python -m asyncioRunning Debug|x64 interpreter...asyncio REPL 3.15.0a1+ (heads/asyncio-repl-handle-python-startup-dirty:ce03ccef689, Nov  8 2025, 02:06:1) [MSC v.1944 64 bit (AMD64)] on win32Use "await" directly instead of "asyncio.run()".Type "help", "copyright", "credits" or "license" for more information.>>> import asyncio>>> exitexiting asyncio REPL...C:\Users\zenon\Python\cpython\Lib\asyncio\base_events.py:758: ResourceWarning: unclosed event loop <ProactorEventLoop running=False closed=False debug=False>

Definitely a bug, we'll track it elsewhere soon.

EDIT: Tracking in#141262

@johnslavikjohnslavikforce-pushed theasyncio-repl-handle-python-startup branch fromb85a31b to0a50a50CompareNovember 8, 2025 12:35
@johnslavikjohnslavik deleted the asyncio-repl-handle-python-startup branchDecember 2, 2025 00:44
@johnslavikjohnslavik restored the asyncio-repl-handle-python-startup branchDecember 5, 2025 12:28
@johnslavikjohnslavik reopened thisDec 5, 2025
@johnslavik
Copy link
ContributorAuthor

johnslavik commentedDec 5, 2025
edited
Loading

This is ready, but Windows doesn't pass because ofGH-141262.

@johnslavikjohnslavik marked this pull request as ready for reviewDecember 5, 2025 12:31
@johnslavik
Copy link
ContributorAuthor

johnslavik commentedDec 16, 2025
edited
Loading

It seems that these unclosed loop warnings regressed (stopped appearing) in the recent releases -- this is bad, but we can fix them separately and we can also fix the asyncio REPL in this regard by actually closing the loop (in a separate PR).

In the meantime, updating this branch should make the CI green.

@johnslavik
Copy link
ContributorAuthor

johnslavik commentedDec 16, 2025
edited
Loading

Looks like I was confused about the regression -- that's good news!

This will have to wait until the loop is properly closed in the asyncio REPL.

@johnslavik
Copy link
ContributorAuthor

Cherry-picked92f629b (875fd2a) fromGH-142785 to see if it fixes the problem.

@johnslavik
Copy link
ContributorAuthor

to see if it fixes the problem.

It does! Cool!

Comment on lines +106 to +107
exceptSystemExit:
raise
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This resembles the original behavior of the REPLs -- seeGH-143023.
I don't think this is correct though. We can remove this as part ofGH-143023.

Suggested change
exceptSystemExit:
raise
# TODO: Revisit in GH-143023
exceptSystemExit:
raise

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This is also why I didn't add a test for this.

@johnslavikjohnslavik marked this pull request as ready for reviewDecember 20, 2025 17:36
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

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

@asvetlovasvetlovAwaiting requested review from asvetlovasvetlov is a code owner

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

1 participant

@johnslavik

[8]ページ先頭

©2009-2025 Movatter.jp