Skip to content
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

Closed
stockbsd mannequin opened this issue Dec 9, 2014 · 10 comments
Closed

uncaught exception in lib/warnings.py when executed with pythonw #67205

stockbsd mannequin opened this issue Dec 9, 2014 · 10 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@stockbsd
Copy link
Mannequin

stockbsd mannequin commented Dec 9, 2014

BPO 23016
Nosy @vstinner, @serhiy-storchaka
Files
  • warnings_stderr_none.patch
  • 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:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2014-12-10.22:08:57.215>
    created_at = <Date 2014-12-09.01:27:03.159>
    labels = ['type-bug', 'library']
    title = 'uncaught exception in lib/warnings.py when executed with pythonw'
    updated_at = <Date 2014-12-14.08:58:48.377>
    user = 'https://bugs.python.org/stockbsd'

    bugs.python.org fields:

    activity = <Date 2014-12-14.08:58:48.377>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2014-12-10.22:08:57.215>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2014-12-09.01:27:03.159>
    creator = 'stockbsd'
    dependencies = []
    files = ['37396']
    hgrepos = []
    issue_num = 23016
    keywords = ['patch']
    message_count = 10.0
    messages = ['232342', '232369', '232371', '232374', '232391', '232424', '232443', '232631', '232632', '232633']
    nosy_count = 5.0
    nosy_names = ['vstinner', 'Arfrever', 'python-dev', 'serhiy.storchaka', 'stockbsd']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue23016'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @stockbsd
    Copy link
    Mannequin Author

    stockbsd mannequin commented Dec 9, 2014

    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.

    @stockbsd stockbsd mannequin added type-crash A hard crash of the interpreter, possibly with a core dump stdlib Python modules in the Lib dir labels Dec 9, 2014
    @serhiy-storchaka
    Copy link
    Member

    Here is a patch. 2.7 is affected too.

    @serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Dec 9, 2014
    @stockbsd
    Copy link
    Mannequin Author

    stockbsd mannequin commented Dec 9, 2014

    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:

    @vstinner
    Copy link
    Member

    vstinner commented Dec 9, 2014

    + execpt:

    Please never use that, but "except Exception:" instead to not catch SystemExit or KeyboardInterrupt.

    @serhiy-storchaka
    Copy link
    Member

    I afraid this will silence unexpected errors.

    @vstinner
    Copy link
    Member

    warnings_stderr_none.patch looks good to me. It can be applied on Python 2.7, 3.4 and 3.5.

    @bitdancer bitdancer changed the title uncatched exception in lib/warnings.py when executed with pythonw uncaught exception in lib/warnings.py when executed with pythonw Dec 10, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 10, 2014

    New changeset d04dab84388f by Serhiy Storchaka in branch '3.4':
    Issue bpo-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 bpo-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 bpo-23016: A warning no longer produces an AttributeError when sys.stderr
    https://hg.python.org/cpython/rev/aeeec8a4b9b8

    @Arfrever
    Copy link
    Mannequin

    Arfrever mannequin commented Dec 14, 2014

    •        # sys.stderr is None when ran with pythonw.exe - warnings get lost
      

    s/ran/run/

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 14, 2014

    New changeset 70b6fe58c425 by Serhiy Storchaka in branch '3.4':
    Fixed a typo in a comment (issue bpo-23016).
    https://hg.python.org/cpython/rev/70b6fe58c425

    New changeset da1ec8e0e068 by Serhiy Storchaka in branch 'default':
    Fixed a typo in a comment (issue bpo-23016).
    https://hg.python.org/cpython/rev/da1ec8e0e068

    @serhiy-storchaka
    Copy link
    Member

    Thanks Arfrever.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants