This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2014年12月09日 01:27 by stockbsd, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| warnings_stderr_none.patch | serhiy.storchaka, 2014年12月09日 11:49 | review | ||
| Messages (10) | |||
|---|---|---|---|
| msg232342 - (view) | Author: stockbsd Li (stockbsd) | Date: 2014年12月09日 01:27 | |
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.
|
|||
| msg232369 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年12月09日 11:49 | |
Here is a patch. 2.7 is affected too. |
|||
| msg232371 - (view) | Author: stockbsd Li (stockbsd) | Date: 2014年12月09日 12:21 | |
1. py2 is unaffected, because stderr/stdout is not None in py2's pythonw and the catch works correctly. 2. as to py3, I prefer this patch: - execpt OSError: + execpt: |
|||
| msg232374 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2014年12月09日 13:10 | |
+ execpt: Please never use that, but "except Exception:" instead to not catch SystemExit or KeyboardInterrupt. |
|||
| msg232391 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年12月09日 16:41 | |
I afraid this will silence unexpected errors. |
|||
| msg232424 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2014年12月10日 13:09 | |
warnings_stderr_none.patch looks good to me. It can be applied on Python 2.7, 3.4 and 3.5. |
|||
| msg232443 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2014年12月10日 21:12 | |
New changeset d04dab84388f by Serhiy Storchaka in branch '3.4': Issue #23016: A warning no longer produces AttributeError when the program https://hg.python.org/cpython/rev/d04dab84388f New changeset 0050e770b34c by Serhiy Storchaka in branch 'default': Issue #23016: A warning no longer produces an AttributeError when the program https://hg.python.org/cpython/rev/0050e770b34c New changeset aeeec8a4b9b8 by Serhiy Storchaka in branch '2.7': Issue #23016: A warning no longer produces an AttributeError when sys.stderr https://hg.python.org/cpython/rev/aeeec8a4b9b8 |
|||
| msg232631 - (view) | Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) | Date: 2014年12月14日 08:15 | |
> + # sys.stderr is None when ran with pythonw.exe - warnings get lost s/ran/run/ |
|||
| msg232632 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2014年12月14日 08:58 | |
New changeset 70b6fe58c425 by Serhiy Storchaka in branch '3.4': Fixed a typo in a comment (issue #23016). https://hg.python.org/cpython/rev/70b6fe58c425 New changeset da1ec8e0e068 by Serhiy Storchaka in branch 'default': Fixed a typo in a comment (issue #23016). https://hg.python.org/cpython/rev/da1ec8e0e068 |
|||
| msg232633 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2014年12月14日 08:58 | |
Thanks Arfrever. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:10 | admin | set | github: 67205 |
| 2014年12月14日 08:58:48 | serhiy.storchaka | set | messages: + msg232633 |
| 2014年12月14日 08:58:06 | python-dev | set | messages: + msg232632 |
| 2014年12月14日 08:15:09 | Arfrever | set | nosy:
+ Arfrever messages: + msg232631 |
| 2014年12月10日 22:08:57 | serhiy.storchaka | set | status: open -> closed assignee: serhiy.storchaka resolution: fixed stage: patch review -> resolved |
| 2014年12月10日 21:12:49 | python-dev | set | nosy:
+ python-dev messages: + msg232443 |
| 2014年12月10日 14:58:24 | r.david.murray | set | title: uncatched exception in lib/warnings.py when executed with pythonw -> uncaught exception in lib/warnings.py when executed with pythonw |
| 2014年12月10日 13:09:22 | vstinner | set | messages: + msg232424 |
| 2014年12月09日 16:41:40 | serhiy.storchaka | set | messages: + msg232391 |
| 2014年12月09日 13:10:45 | vstinner | set | nosy:
+ vstinner messages: + msg232374 |
| 2014年12月09日 12:21:16 | stockbsd | set | messages: + msg232371 |
| 2014年12月09日 11:49:40 | serhiy.storchaka | set | files:
+ warnings_stderr_none.patch type: crash -> behavior versions: + Python 2.7, Python 3.5, - Python 3.2, Python 3.3 keywords: + patch nosy: + serhiy.storchaka messages: + msg232369 stage: patch review |
| 2014年12月09日 01:27:03 | stockbsd | create | |