MAINT: Convert umath_linalg to multi-phase init (PEP 489) by AA-Turner · Pull Request #29030 · numpy/numpy

As far as I can tell, importing numpy simply fails in a subinterpreter, and continues to do so with the explicit opt-out.

$ uvx --with numpy --python 3.13 python
Python 3.13.3+ (main, May 20 2025, 08:56:23) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import _interpreters
>>> # first import in an interpreter with a 'legacy' shared GIL
>>> c = _interpreters.new_config('legacy')  
>>> id1 = _interpreters.create(c, reqrefs=True)
>>> _interpreters.incref(id1)  # bookkeeping
>>> _interpreters.exec(id1, 'import sys', restrict=True)  # stdlib works
>>> _interpreters.exec(id1, 'import numpy', restrict=True)
namespace(
  type=namespace(
    __name__='RuntimeError',
    __qualname__='RuntimeError',
    __module__='builtins'
  ), 
  msg='CPU dispatcher tracer already initlized',
  formatted='RuntimeError: CPU dispatcher tracer already initlized',
  errdisplay='Traceback (most recent call last):\n  File "<string>", line 1, in <module>\n'
             '[...SNIP...]\n'
             '    from numpy._core._multiarray_umath import (\n'
             '        add_docstring,  _get_implementing_args, _ArrayFunctionDispatcher)\n'
             'RuntimeError: CPU dispatcher tracer already initlized'
)
>>> # now import in an isolated interpreter with its own GIL
>>> id2 = _interpreters.create(reqrefs=True)
>>> _interpreters.exec(id2, 'import sys', restrict=True)
>>> print(_interpreters.exec(id2, 'import numpy', restrict=True))
double free or corruption (out)
$  # the REPL has crashed!

Reloading currently works with a UserWarning, unchanged with the explict opt-out.

The observable change I've found is clearing sys.modules and re-importing. Previously, it emitted UserWarning: The NumPy module was reloaded (imported a second time). This can in some cases result in small but subtle issues and is discouraged., but would now raise ImportError: cannot load module more than once per process.