Skip to content

Conversation

@johnslavik
Copy link
Contributor

@johnslavik johnslavik commented Oct 18, 2025

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

@johnslavik
Copy link
Contributor Author

Please merge #140298 first.

@johnslavik johnslavik marked this pull request as ready for review October 23, 2025 14:57
@johnslavik johnslavik marked this pull request as draft October 23, 2025 15:00
# Isolated mode implies -E, -P and -s, purifies sys.path and ignores PYTHON*
# variables.
if isolated:
cmd_line.append('-I')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To reuse this routine and spawn_asyncio_repl below, we need to have a knob to not pass -I since that ignores PYTHONSTARTUP completely.

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

Copy link
Contributor Author

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
def test_asyncio_repl_reaches_python_startup_script(self):
with os_helper.temp_dir() as tmpdir:
script = os.path.join(tmpdir, "pythonstartup.py")
with open(script, "w") as f:
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
Contributor Author

Choose a reason for hiding this comment

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

Covered by TestPythonStartup now, so not needed here.

@johnslavik johnslavik closed this Dec 2, 2025
@johnslavik johnslavik deleted the asyncio-repl-handle-python-startup branch December 2, 2025 00:44
@johnslavik johnslavik restored the asyncio-repl-handle-python-startup branch December 5, 2025 12:28
@johnslavik johnslavik reopened this Dec 5, 2025
@johnslavik
Copy link
Contributor Author

johnslavik commented Dec 5, 2025

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

@johnslavik johnslavik marked this pull request as ready for review December 5, 2025 12:31
@johnslavik
Copy link
Contributor Author

johnslavik commented Dec 16, 2025

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
Contributor Author

johnslavik commented Dec 16, 2025

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
Contributor Author

Cherry-picked 92f629b (875fd2a) from GH-142785 to see if it fixes the problem.

@johnslavik
Copy link
Contributor Author

to see if it fixes the problem.

It does! Cool!

Comment on lines +106 to +107
except SystemExit:
raise
Copy link
Contributor Author

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 -- see GH-143023.
I don't think this is correct though. We can remove this as part of GH-143023.

Suggested change
except SystemExit:
raise
# TODO: Revisit in GH-143023
except SystemExit:
raise

Copy link
Contributor Author

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.

@johnslavik johnslavik marked this pull request as ready for review December 20, 2025 17:36
@johnslavik
Copy link
Contributor Author

I'll see if I can simplify this. I think the tests are slightly overcomplicated.

@johnslavik johnslavik marked this pull request as draft December 21, 2025 16:02
Copy link
Contributor Author

@johnslavik johnslavik left a comment

Choose a reason for hiding this comment

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

I'll come back to this after completing GH-140648.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant