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
py launcher stderr is not piped to subprocess.Popen.stderr #69975
Comments
from the console:
or any other not installed Python version gives: However, when the launcher is executed from python via subprocess.Popen:
the error message is not accessible. (Error messages from any successfully launched Python interpreter are available through p.stderr though.) |
The error() function in PC/launcher.c should call exit(rc) instead of ExitProcess(rc). This allows the CRT to terminate properly and flush the stderr FILE stream. With this change it works as expected: >>> import subprocess
>>> p = subprocess.Popen(r'amd64\py_d -3.7', stderr=subprocess.PIPE)
>>> p.stderr.read()
b'Requested Python version (3.7) not installed\r\n' |
Interesting. Why do you need to flush stderr? I would have expected it to be unbuffered in the first place. What's the usecase/advantage of calling ExitProcess then? |
ExitProcess is a system API and exit is the C runtime API. The C runtime is doing the buffering, so the system doesn't know about it and can't flush if you terminate through that API. The exit function should, or we could explicitly flush the buffer after writing to it. |
Patch 2 additionally modifies run_child to call exit() instead of ExitProcess. For example: >>> import os, subprocess
>>> os.environ['PYLAUNCH_DEBUG'] = '1'
>>> p = subprocess.Popen(r'py -3 -c ""', stderr=subprocess.PIPE, stdout=subprocess.PIPE)
>>> p.stderr.read()
b'' Patched: >>> p = subprocess.Popen(r'amd64\py_d -3 -c ""', stderr=subprocess.PIPE, stdout=subprocess.PIPE)
>>> p.stderr.readlines()[-1]
b'child process exit code: 0\r\n' For good measure I also added a call to setvbuf to disable buffering stderr. |
New changeset d0a84d0c5ceb by Vinay Sajip in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: