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

"SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error" from open function #74811

Closed
pppery mannequin opened this issue Jun 10, 2017 · 7 comments
Assignees
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir topic-IO type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@pppery
Copy link
Mannequin

pppery mannequin commented Jun 10, 2017

BPO 30626
Nosy @brettcannon, @ncoghlan, @benjaminp, @ericsnowcurrently, @serhiy-storchaka, @pppery
PRs
  • bpo-30626: Fix error handling in PyImport_Import(). #2103
  • [3.6] bpo-30626: Fix error handling in PyImport_Import(). (GH-2103) #2221
  • [3.5] bpo-30626: Fix error handling in PyImport_Import(). (GH-2103) #2222
  • 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 2017-06-15.18:21:52.337>
    created_at = <Date 2017-06-10.18:53:58.796>
    labels = ['interpreter-core', '3.7', 'library', 'expert-IO', 'type-crash']
    title = '"SystemError: <class \'_io.TextIOWrapper\'> returned NULL without setting an error"  from open function'
    updated_at = <Date 2017-06-15.18:21:52.336>
    user = 'https://github.com/pppery'

    bugs.python.org fields:

    activity = <Date 2017-06-15.18:21:52.336>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2017-06-15.18:21:52.337>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core', 'Library (Lib)', 'IO']
    creation = <Date 2017-06-10.18:53:58.796>
    creator = 'ppperry'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30626
    keywords = []
    message_count = 7.0
    messages = ['295654', '295680', '295681', '295693', '296118', '296119', '296120']
    nosy_count = 7.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'benjamin.peterson', 'stutzbach', 'eric.snow', 'serhiy.storchaka', 'ppperry']
    pr_nums = ['2103', '2221', '2222']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue30626'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @pppery
    Copy link
    Mannequin Author

    pppery mannequin commented Jun 10, 2017

    This code (reduced from an example I had of trying to debug code including the module-level code of already imported modules), raises a SystemError:
    import builtins
    from importlib.machinery import PathFinder
    from importlib.util import find_spec
    import importlib
    import sys
    import _imp
    dct={}
    def copy_module(module):
    new = type(sys)(module.__name__)
    new.__dict__.update(module.__dict__)
    return new

    dct["__builtins__"] = b = copy_module(builtins)

    spec = PathFinder.find_spec("_bootstrap",importlib.__path__)
    source_bootstrap = type(sys)("_bootstrap");
    spec.loader.exec_module(source_bootstrap);
    source_bootstrap.__name__ = "importlib._bootstrap";    
    new_sys = copy_module(sys)
    
    new_sys.path_hooks = []
    new_sys.meta_path = []
    new_sys.modules = {
        "importlib._bootstrap":source_bootstrap,
        "importlib._bootstrap_external":importlib._bootstrap_external,
    }
    b.__import__ = source_bootstrap.__import__
    source_bootstrap._install(new_sys,_imp)
    dct["__file__"]=__file__
    exec("open(__file__)",dct)

    The actual file passed to the open function doesn't matter, as long as it would work

    @pppery pppery mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir topic-IO labels Jun 10, 2017
    @pppery pppery mannequin changed the title "SystemError: SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error "SystemError: SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error" from open function Jun 10, 2017
    @pppery pppery mannequin changed the title "SystemError: SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error" from open function "SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error" from open function Jun 10, 2017
    @pppery pppery mannequin added the type-bug An unexpected behavior, bug, or error label Jun 10, 2017
    @ncoghlan
    Copy link
    Contributor

    I couldn't reproduce this on 3.7, but I can confirm that 3.6 gives a SystemError with the above code:

    $ ./python _issue30626.py
    Traceback (most recent call last):
      File "_issue30626.py", line 30, in <module>
        exec("open(__file__)",dct)
      File "<string>", line 1, in <module>
    SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error

    It's plausible this was fixed as part of the interpreter startup refactoring, so I doubt we're going to able to easily isolate the specific change that fixed it :(

    @ncoghlan
    Copy link
    Contributor

    That said: given that we know it *is* fixed somewhere in 3.7, it would likely be useful to check the assumption that the startup refactoring fixed it by going to the last commit before that landed and seeing if the error still occurs.

    @serhiy-storchaka serhiy-storchaka self-assigned this Jun 11, 2017
    @serhiy-storchaka serhiy-storchaka added type-crash A hard crash of the interpreter, possibly with a core dump and removed type-bug An unexpected behavior, bug, or error labels Jun 11, 2017
    @serhiy-storchaka
    Copy link
    Member

    In rare circumstances PyImport_Import() could return NULL without raising an error.

    It *isn't* fixed in 3.7.

    @serhiy-storchaka serhiy-storchaka added the 3.7 (EOL) end of life label Jun 11, 2017
    @serhiy-storchaka
    Copy link
    Member

    New changeset 145541c by Serhiy Storchaka in branch 'master':
    bpo-30626: Fix error handling in PyImport_Import(). (bpo-2103)
    145541c

    @serhiy-storchaka
    Copy link
    Member

    New changeset fab05de by Serhiy Storchaka in branch '3.6':
    [3.6] bpo-30626: Fix error handling in PyImport_Import(). (GH-2103) (bpo-2221)
    fab05de

    @serhiy-storchaka
    Copy link
    Member

    New changeset 263dcc3 by Serhiy Storchaka in branch '3.5':
    [3.5] bpo-30626: Fix error handling in PyImport_Import(). (GH-2103) (bpo-2222)
    263dcc3

    @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
    3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) stdlib Python modules in the Lib dir topic-IO type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants