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: <built-in function create_builtin> returned NULL without setting an error from importing _pickle on Windows #75056

Closed
pppery mannequin opened this issue Jul 8, 2017 · 5 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) OS-windows stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@pppery
Copy link
Mannequin

pppery mannequin commented Jul 8, 2017

BPO 30873
Nosy @brettcannon, @pfmoore, @ncoghlan, @vstinner, @tjguk, @ericsnowcurrently, @zware, @serhiy-storchaka, @zooba, @pppery
Superseder
  • bpo-30626: "SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error" from open function
  • 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 2017-07-10.12:52:47.915>
    created_at = <Date 2017-07-08.02:29:24.594>
    labels = ['interpreter-core', 'type-bug', 'library', 'OS-windows']
    title = '`SystemError: <built-in function create_builtin> returned NULL without setting an  error` from importing _pickle on Windows'
    updated_at = <Date 2017-07-10.12:52:47.913>
    user = 'https://github.com/pppery'

    bugs.python.org fields:

    activity = <Date 2017-07-10.12:52:47.913>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-07-10.12:52:47.915>
    closer = 'vstinner'
    components = ['Interpreter Core', 'Library (Lib)', 'Windows']
    creation = <Date 2017-07-08.02:29:24.594>
    creator = 'ppperry'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30873
    keywords = []
    message_count = 5.0
    messages = ['297924', '297941', '297953', '297954', '298062']
    nosy_count = 10.0
    nosy_names = ['brett.cannon', 'paul.moore', 'ncoghlan', 'vstinner', 'tim.golden', 'eric.snow', 'zach.ware', 'serhiy.storchaka', 'steve.dower', 'ppperry']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '30626'
    type = 'behavior'
    url = 'https://bugs.python.org/issue30873'
    versions = ['Python 3.6']

    @pppery
    Copy link
    Mannequin Author

    pppery mannequin commented Jul 8, 2017

    The following rather long code, reduced from the same example as bpo-30626, produces a SystemError:

    import builtins
    from importlib.machinery import PathFinder
    import importlib
    import sys
    import _imp
    from functools import partial
    def copy_module(module):
        new = type(sys)(module.__name__)
        new.__dict__.update(module.__dict__)
        return new
    _absent = object()
    def new_exec(code, globals=_absent, locals=_absent, *, new_builtins):
        if globals == _absent:
            frame = sys._getframe(2)
            globals = frame.f_globals
            locals = frame.f_locals
        elif locals == _absent:
            locals = globals
        globals.setdefault("__builtins__", new_builtins);
        return exec(code, globals, locals)
    dct={}
    dct["__builtins__"] = b = copy_module(builtins)
    b.exec = partial(new_exec, new_builtins=b)
    spec = PathFinder.find_spec("_bootstrap",importlib.__path__)
    source_bootstrap = type(sys)("_bootstrap");
    spec.loader.exec_module(source_bootstrap);
    external_spec = PathFinder.find_spec("_bootstrap_external",importlib.__path__)
    source_bootstrap_external = type(sys)("_bootstrap_external");
    external_spec.loader.exec_module(source_bootstrap_external);
    source_bootstrap.__name__ = "importlib._bootstrap";
    source_bootstrap_external.__name__ = "importlib._bootstrap_external";
    new_sys = copy_module(sys)
    new_sys.path_importer_cache = {}
    new_sys.path_hooks = []
    new_sys.meta_path = []
    new_sys.modules = {
                        "importlib._bootstrap":source_bootstrap,
                        "importlib._bootstrap_external":source_bootstrap_external,
                      }
    for mod in new_sys.modules.values():
        mod.__builtins__ = b
    b.__import__ = source_bootstrap.__import__
    source_bootstrap._install(new_sys,_imp)
    exec("import _pickle", dct)

    @pppery pppery mannequin added stdlib Python modules in the Lib dir interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jul 8, 2017
    @pppery pppery mannequin changed the title SystemError: <built-in function create_builtin> returned NULL without setting an error from imp.create_builtin SystemError: <built-in function create_builtin> returned NULL without setting an error from importing _pickle Jul 8, 2017
    @serhiy-storchaka
    Copy link
    Member

    I get the following error on 3.7:

    $ ./python issue30873.py 
    Traceback (most recent call last):
      File "issue30873.py", line 44, in <module>
        exec("import _pickle", dct)
      File "<string>", line 1, in <module>
      File "/home/serhiy/py/cpython/Lib/importlib/_bootstrap.py", line 1059, in __import__
        module = _gcd_import(name)
      File "/home/serhiy/py/cpython/Lib/importlib/_bootstrap.py", line 986, in _gcd_import
        return _find_and_load(name, _gcd_import)
      File "/home/serhiy/py/cpython/Lib/importlib/_bootstrap.py", line 963, in _find_and_load
        return _find_and_load_unlocked(name, import_)
      File "/home/serhiy/py/cpython/Lib/importlib/_bootstrap.py", line 948, in _find_and_load_unlocked
        raise ModuleNotFoundError(_ERR_MSG.format(name), name=name)
    ModuleNotFoundError: No module named '_pickle'

    On 3.6:

    $ ./python issue30873.py 
    Traceback (most recent call last):
      File "issue30873.py", line 44, in <module>
        exec("import _pickle", dct)
      File "<string>", line 1, in <module>
      File "/home/serhiy/py/cpython3.6/Lib/importlib/_bootstrap.py", line 1059, in __import__
        module = _gcd_import(name)
      File "/home/serhiy/py/cpython3.6/Lib/importlib/_bootstrap.py", line 986, in _gcd_import
        return _find_and_load(name, _gcd_import)
      File "/home/serhiy/py/cpython3.6/Lib/importlib/_bootstrap.py", line 963, in _find_and_load
        return _find_and_load_unlocked(name, import_)
      File "/home/serhiy/py/cpython3.6/Lib/importlib/_bootstrap.py", line 950, in _find_and_load_unlocked
        module = _load_unlocked(spec)
      File "/home/serhiy/py/cpython3.6/Lib/importlib/_bootstrap.py", line 648, in _load_unlocked
        module = module_from_spec(spec)
      File "/home/serhiy/py/cpython3.6/Lib/importlib/_bootstrap.py", line 560, in module_from_spec
        module = spec.loader.create_module(spec)
      File "<frozen importlib._bootstrap_external>", line 922, in create_module
      File "/home/serhiy/py/cpython3.6/Lib/importlib/_bootstrap.py", line 205, in _call_with_frames_removed
        return f(*args, **kwds)
    KeyError: 'copyreg'

    @pppery
    Copy link
    Mannequin Author

    pppery mannequin commented Jul 8, 2017

    Interesting. For you, _pickle seems to be an extension module, which is thus trying to call imp.create_dynamic, whereas for me it is a builtin module. Perhaps that explains why you get a KeyError and I get a SystemError (my traceback ends with):
    File "C:\Program Files\Python36\lib\importlib_bootstrap.py", line 560, in module_from_spec
    module = spec.loader.create_module(spec)
    File "C:\Program Files\Python36\lib\importlib_bootstrap.py", line 725, in create_module
    return _call_with_frames_removed(_imp.create_builtin, spec)
    File "C:\Program Files\Python36\lib\importlib_bootstrap.py", line 205, in _call_with_frames_removed
    return f(*args, **kwds)
    SystemError: returned NULL without setting an error
    (and is the same as your 3.6 traceback up to that point)

    @serhiy-storchaka
    Copy link
    Member

    Ah, this is Windows-only _imp.create_builtin().

    @pppery pppery mannequin changed the title SystemError: <built-in function create_builtin> returned NULL without setting an error from importing _pickle SystemError: <built-in function create_builtin> returned NULL without setting an error from importing _pickle on Windows Jul 8, 2017
    @vstinner
    Copy link
    Member

    ppperry: First, please create a Python script and attach it to the issue, it would make it easier to reproduce the bug. Second, which Python version did you test? I tested 3.6 and master Git branches on Windows, and I'm unable to reproduce the bug.

    I'm able to reproduce the bug on Windows using Python 3.6.1, but this version still contains bpo-30626 bug. I'm unable to reproduce the bug using 3.6.2rc2, so to be, this bug is just a duplicate of bpo-30626.

    Please try: https://www.python.org/downloads/release/python-362rc2/

    @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) OS-windows 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