gh-117953: Always Run Extension Init Func in Main Interpreter First by ericsnowcurrently · Pull Request #118157 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions Lib/test/test_import/__init__.py
7 changes: 4 additions & 3 deletions Lib/test/test_interpreters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from test.support import load_package_tests
from test.support import load_package_tests, Py_GIL_DISABLED

def load_tests(*args):
return load_package_tests(os.path.dirname(__file__), *args)
if not Py_GIL_DISABLED:
def load_tests(*args):
return load_package_tests(os.path.dirname(__file__), *args)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
When a builtin or extension module is imported for the first time, while a
subinterpreter is active, the module's init function is now run by the main
interpreter first before import continues in the subinterpreter.
Consequently, single-phase init modules now fail in an isolated
subinterpreter without the init function running under that interpreter,
whereas before it would run under the subinterpreter *before* failing,
potentially leaving behind global state and callbacks and otherwise leaving
the module in an inconsistent state.
252 changes: 197 additions & 55 deletions Python/import.c