-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
argparse: Check if stderr is defined before writing to it #101640
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
Comments
* In particular, don't exit when trying to print to stderr = None. * Add tests Co-authored-by: Terry Jan Reedy <[email protected]>
…ythonGH-101802) * In particular, don't exit when trying to print to stderr = None. * Add tests (cherry picked from commit 42f54d1) Co-authored-by: Oleg Iarygin <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]>
@simaoafonso-pwt The title of the 3.11 backport says specifically what was done. Without a stacktrace, we cannot be sure that this was the site of the error. And even if it was, whether this is sufficient to fix this issue for you. If you can, please make a new binary (after the 3.11 merge) and see if it now works. And report here so we can either close or look further (given a traceback and message). |
…H-101802) (#104250) gh-101640: Make argparse _print_message catch any write error (GH-101802) * In particular, don't exit when trying to print to stderr = None. * Add tests (cherry picked from commit 42f54d1) Co-authored-by: Oleg Iarygin <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]>
Sorry, is there some kind of nightly build I could use to test this? Compiling Python on Windows is not something I'm very comfortable with. |
…ython#101802) * In particular, don't exit when trying to print to stderr = None. * Add tests Co-authored-by: Terry Jan Reedy <[email protected]>
You can follow https://devguide.python.org/getting-started/ to get the latest sources and build them. The prebuilt executable will be availible as CPython 3.12b1 on May 22. |
I tried to check this, but it seems PyInstaller is not yet 3.12-ready, it might take a longer time: pyinstaller/pyinstaller#7601 |
I am closing for now. This can be reopened or a new issue opened if later found necessary. |
Compiling on Windows is pretty easy now if one has git installed. Clone python/cpython. Install VS 2022 with python extension exactly as detailed in devguide. Give command line, I believe |
This is already closed, but only now I got time to check this, now that PyInstaller published wheels for 3.12, and can confirm this is fixed in |
FYI, in case you need a workaround for this issue on lower Python versions, you can use this: # Workaround for https://github.com/python/cpython/issues/101640
if sys.version_info >= (3, 12):
ArgumentParser = argparse.ArgumentParser
else:
class ArgumentParser(argparse.ArgumentParser):
def _print_message(self, message, file=None):
if file is None:
pass # Don't print if the file is unavailable
else:
super()._print_message(message, file=file) Then use |
Bug report
argparse
tries to write to stderr inconditionally, even when it'sNone
. This is only a problem on Windows. Here:https://github.com/python/cpython/blob/3.11/Lib/argparse.py#L2596-L2600
I detected this when using PyInstaller to create a binary on Windows using
--noconsole
, which triggers usingpythonw.exe
. In this case,sys.stderr is None
.This is similar to #89057
Your environment
Linked PRs
pythonw
by dropping stderr writes there #101802The text was updated successfully, but these errors were encountered: