- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.3k
          gh-140287: Handle PYTHONSTARTUP 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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| Please merge #140298 first. | 
| # Isolated mode implies -E, -P and -s, purifies sys.path and ignores PYTHON* | ||
| # variables. | ||
| if isolated: | ||
| cmd_line.append('-I') | 
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.
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.
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.
Tracking the -I edge case in #140648.
| 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, | ||
| ) | 
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.
Covered by TestPythonStartup now, so not needed here.
| I've gotten a little background on precedent changes to this region of the tests code. | 
| for expected in ( | ||
| "Traceback (most recent call last):", | ||
| 'File "<stdin>", line 1, in <module>', | ||
| f'File "{startup_env['PYTHONSTARTUP']}", line ', | 
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.
I need to understand why line number 2 fails specifically on Windows and 3 is expected.
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.
I'm also thinking that ideally we would test stdout and stderr separately.
This is generally a work in progress; tests are needed.
The asyncio patch is simple and ready.
PYTHONSTARTUPexceptions #140287