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

mywrite() ignores PyFile_WriteString() errors #52371

Closed
vstinner opened this issue Mar 12, 2010 · 7 comments
Closed

mywrite() ignores PyFile_WriteString() errors #52371

vstinner opened this issue Mar 12, 2010 · 7 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@vstinner
Copy link
Member

BPO 8124
Nosy @vstinner
Files
  • mywrite_nosignal.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 = None
    closed_at = <Date 2010-04-23.12:05:11.764>
    created_at = <Date 2010-03-12.16:08:37.945>
    labels = ['interpreter-core', 'type-bug']
    title = 'mywrite() ignores PyFile_WriteString() errors'
    updated_at = <Date 2010-04-23.12:05:11.762>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2010-04-23.12:05:11.762>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-04-23.12:05:11.764>
    closer = 'vstinner'
    components = ['Interpreter Core']
    creation = <Date 2010-03-12.16:08:37.945>
    creator = 'vstinner'
    dependencies = []
    files = ['17045']
    hgrepos = []
    issue_num = 8124
    keywords = ['patch']
    message_count = 7.0
    messages = ['100939', '100942', '103711', '103946', '103948', '103949', '104006']
    nosy_count = 1.0
    nosy_names = ['vstinner']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue8124'
    versions = ['Python 3.1', 'Python 3.2']

    @vstinner
    Copy link
    Member Author

    PyFile_WriteString() calls PyObject_Str() which calls PyErr_CheckSignals(). If a signal was catched, the signal handler is called. If the signal handler raises an error, PyObject_Str() and then PyFile_WriteString() return NULL.

    mywrite() ignores all PyFile_WriteString() errors. It should maybe only ignores errors from the file (except IOError: ...) and not any error.

    Another problem: mywrite() is called from PySys_WriteStdout() and PySys_WriteStderr() which are procedures. PySys_WriteStdout()/PySys_WriteStderr() caller cannot detect the error. There are 65 calls to PySys_WriteStd...

    @vstinner vstinner added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Mar 12, 2010
    @vstinner
    Copy link
    Member Author

    This bug is related to bpo-3137.

    @vstinner
    Copy link
    Member Author

    Another solution: disable call to PyErr_CheckSignals() in mywrite().

    @vstinner
    Copy link
    Member Author

    Attached patch fixes this issue: PyFile_WriteObject() doesn't call PyObject_Str() to avoid PyErr_CheckSignals(). I'm not sure that it's the right approch because it may change the behaviour of existing code when getting a signal.

    @vstinner
    Copy link
    Member Author

    Ok, forget my pyfile_writeobject_nosignal.patch, it's not the right approach.

    New patch: mywrite() uses its own implementation PyFile_WriteString(), sys_pyfile_write(), which doesn't call PyErr_CheckSignals():

    /* Implementation of PyFile_WriteString() no calling PyErr_CheckSignals():

    • mywrite() should not execute any Python signal handler to avoid raising an
    • error because mywrite() ignores all errors */

    @vstinner
    Copy link
    Member Author

    The goal is this issue is also to catch SIGINT when starting Python. It now works in Python trunk and py3k, but not in verbose mode because mywrite() eats errors (especially the KeyboardInterrupt raised by the default SIGINT handler) and calls indirectly Python signal handlers.

    @vstinner
    Copy link
    Member Author

    Commited: r80404 (py3k), r80405 (3.1).

    @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
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant