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
uncaught exception in lib/warnings.py when executed with pythonw #67205
Comments
in py3k, the following simple code will throw an uncatched exception when executed with pythonw: import warnings
warnings.warn('test') the problem occurs in showarning function: in py3k's pythonw , stderr/stdout is set to None, so the file.write(...) statement will thorw AttributeError uncatched. I think a catch-all except(delete 'OSError') can solve this. def showwarning(message, category, filename, lineno, file=None, line=None):
"""Hook to write a warning to a file; replace if you like."""
if file is None:
file = sys.stderr
try:
file.write(formatwarning(message, category, filename, lineno, line))
except OSError:
pass # the file (probably stderr) is invalid - this warning gets lost. |
Here is a patch. 2.7 is affected too. |
|
+ execpt: Please never use that, but "except Exception:" instead to not catch SystemExit or KeyboardInterrupt. |
I afraid this will silence unexpected errors. |
warnings_stderr_none.patch looks good to me. It can be applied on Python 2.7, 3.4 and 3.5. |
New changeset d04dab84388f by Serhiy Storchaka in branch '3.4': New changeset 0050e770b34c by Serhiy Storchaka in branch 'default': New changeset aeeec8a4b9b8 by Serhiy Storchaka in branch '2.7': |
s/ran/run/ |
New changeset 70b6fe58c425 by Serhiy Storchaka in branch '3.4': New changeset da1ec8e0e068 by Serhiy Storchaka in branch 'default': |
Thanks Arfrever. |
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: