Issue 30626: "SystemError: <class '_io.TextIOWrapper'> returned NULL without setting an error" from open function (original) (raw)

Created on 2017-06-10 18:53 by ppperry, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2103 merged serhiy.storchaka,2017-06-11 08:13
PR 2221 merged serhiy.storchaka,2017-06-15 17:56
PR 2222 merged serhiy.storchaka,2017-06-15 17:57
Messages (7)
msg295654 - (view) Author: (ppperry) Date: 2017-06-10 18:57
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
msg295680 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2017-06-11 01:48
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 exec("open(__file__)",dct) File "", line 1, in 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 :(
msg295681 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2017-06-11 01:49
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.
msg295693 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-11 08:16
In rare circumstances PyImport_Import() could return NULL without raising an error. It *isn't* fixed in 3.7.
msg296118 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-15 17:54
New changeset 145541cfa05394c38cfd64c0be2c5fb382860995 by Serhiy Storchaka in branch 'master': bpo-30626: Fix error handling in PyImport_Import(). (#2103) https://github.com/python/cpython/commit/145541cfa05394c38cfd64c0be2c5fb382860995
msg296119 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-15 18:15
New changeset fab05de21480fc54a5101cf813195cb32724b5ad by Serhiy Storchaka in branch '3.6': [3.6] bpo-30626: Fix error handling in PyImport_Import(). (GH-2103) (#2221) https://github.com/python/cpython/commit/fab05de21480fc54a5101cf813195cb32724b5ad
msg296120 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-15 18:15
New changeset 263dcc39daa74066c2b2fcb007a4bd4f7ec65073 by Serhiy Storchaka in branch '3.5': [3.5] bpo-30626: Fix error handling in PyImport_Import(). (GH-2103) (#2222) https://github.com/python/cpython/commit/263dcc39daa74066c2b2fcb007a4bd4f7ec65073
History
Date User Action Args
2022-04-11 14:58:47 admin set github: 74811
2017-07-10 12:52:47 vstinner link issue30873 superseder
2017-06-15 18:21:52 serhiy.storchaka set status: open -> closedresolution: fixedstage: patch review -> resolved
2017-06-15 18:15:29 serhiy.storchaka set messages: +
2017-06-15 18:15:13 serhiy.storchaka set messages: +
2017-06-15 17:57:00 serhiy.storchaka set pull_requests: + <pull%5Frequest2267>
2017-06-15 17:56:07 serhiy.storchaka set pull_requests: + <pull%5Frequest2266>
2017-06-15 17:54:40 serhiy.storchaka set messages: +
2017-06-11 08:16:09 serhiy.storchaka set stage: needs patch -> patch reviewmessages: + versions: + Python 3.7
2017-06-11 08:13:09 serhiy.storchaka set pull_requests: + <pull%5Frequest2157>
2017-06-11 05:36:25 serhiy.storchaka set assignee: serhiy.storchakatype: behavior -> crashnosy: + serhiy.storchakaversions: + Python 3.5
2017-06-11 01:49:52 ncoghlan set messages: +
2017-06-11 01:48:12 ncoghlan set stage: needs patchmessages: + versions: + Python 3.6
2017-06-10 19:00:50 ppperry set type: behavior
2017-06-10 18:58:41 ppperry set 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
2017-06-10 18:58:28 ppperry set nosy: + brett.cannon, ncoghlan, benjamin.peterson, stutzbach, eric.snow
2017-06-10 18:57:30 ppperry set messages: + components: + Interpreter Core, Library (Lib), IOtitle: "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
2017-06-10 18:53:58 ppperry create