@@ -941,8 +941,15 @@ find and load modules.
941
941
The *fullname * argument specifies the name of the module the loader is to
942
942
support. The *path * argument is the path to the extension module's file.
943
943
944
+ Note that, by default, importing an extension module will fail
945
+ in subinterpreters if it doesn't implement multi-phase init
946
+ (see :pep: `489 `), even if it would otherwise import successfully.
947
+
944
948
.. versionadded :: 3.3
945
949
950
+ .. versionchanged :: 3.12
951
+ Multi-phase init is now required for use in subinterpreters.
952
+
946
953
.. attribute :: name
947
954
948
955
Name of the module the loader supports.
@@ -1248,6 +1255,30 @@ an :term:`importer`.
1248
1255
1249
1256
.. versionadded :: 3.7
1250
1257
1258
+ .. function :: _incompatible_extension_module_restrictions(*, disable_check)
1259
+
1260
+ A context manager that can temporarily skip the compatibility check
1261
+ for extension modules. By default the check is enabled and will fail
1262
+ when a single-phase init module is imported in a subinterpreter.
1263
+ It will also fail for a multi-phase init module that doesn't
1264
+ explicitly support a per-interpreter GIL, when imported
1265
+ in an interpreter with its own GIL.
1266
+
1267
+ Note that this function is meant to accommodate an unusual case;
1268
+ one which is likely to eventually go away. There's is a pretty good
1269
+ chance this is not what you were looking for.
1270
+
1271
+ You can get the same effect as this function by implementing the
1272
+ basic interface of multi-phase init (:pep: `489 `) and lying about
1273
+ support for mulitple interpreters (or per-interpreter GIL).
1274
+
1275
+ .. warning ::
1276
+ Using this function to disable the check can lead to
1277
+ unexpected behavior and even crashes. It should only be used during
1278
+ extension module development.
1279
+
1280
+ .. versionadded :: 3.12
1281
+
1251
1282
.. class :: LazyLoader(loader)
1252
1283
1253
1284
A class which postpones the execution of the loader of a module until the
0 commit comments