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

BUG: test_lazy_load raises RecursionError with Python 3.13.0a5 #26093

Closed
befeleme opened this issue Mar 20, 2024 · 8 comments
Closed

BUG: test_lazy_load raises RecursionError with Python 3.13.0a5 #26093

befeleme opened this issue Mar 20, 2024 · 8 comments
Labels

Comments

@befeleme
Copy link

Describe the issue:

I try to build numpy 1.26.4 in Fedora Linux with Python 3.13.0a5 containing the fix for @LIBPYTHON@ usage (python/cpython#116746). test_lazy_load unexpectedly raises Recursion Error.

Reproduce the code example:

none

Error message:

________________________________ test_lazy_load ________________________________

    @pytest.mark.filterwarnings("ignore:The NumPy module was reloaded")
    def test_lazy_load():
        # gh-22045. lazyload doesn't import submodule names into the namespace
        # muck with sys.modules to test the importing system
        old_numpy = sys.modules.pop("numpy")
    
        numpy_modules = {}
        for mod_name, mod in list(sys.modules.items()):
            if mod_name[:6] == "numpy.":
                numpy_modules[mod_name] = mod
                sys.modules.pop(mod_name)
    
        try:
            # create lazy load of numpy as np
            spec = find_spec("numpy")
            module = module_from_spec(spec)
            sys.modules["numpy"] = module
            loader = LazyLoader(spec.loader)
            loader.exec_module(module)
            np = module
    
            # test a subpackage import
>           from numpy.lib import recfunctions

loader     = <importlib.util.LazyLoader object at 0x7f07a3f64c80>
mod        = <module 'pydoc' from '/usr/lib64/python3.13/pydoc.py'>
mod_name   = 'pydoc'
module     = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
np         = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
numpy_modules = {'numpy.__config__': <module 'numpy.__config__' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/p...lddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/core/_dtype_ctypes.py'>, ...}
old_numpy  = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
spec       = ModuleSpec(name='numpy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, origin='/build...ule_search_locations=['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy'])

../../../../BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/tests/test_lazyloading.py:30: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
<frozen importlib._bootstrap>:1360: in _find_and_load
    ???
        import_    = <built-in function __import__>
        module     = <object object at 0x7f07ea940060>
        name       = 'numpy.lib'
<frozen importlib._bootstrap>:1316: in _find_and_load_unlocked
    ???
        import_    = <built-in function __import__>
        name       = 'numpy.lib'
        parent     = 'numpy'
        parent_module = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
        parent_spec = None
        path       = None
<frozen importlib.util>:209: in __getattribute__
    ???
        __dict__   = {'AxisError': <class 'numpy.exceptions.AxisError'>, 'ComplexWarning': <class 'numpy.exceptions.ComplexWarning'>, 'Modu...ng': <class 'numpy.exceptions.ModuleDeprecationWarning'>, 'TooHardError': <class 'numpy.exceptions.TooHardError'>, ...}
        __spec__   = ModuleSpec(name='numpy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, origin='/build...ule_search_locations=['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy'])
        attr       = '__path__'
        attrs_now  = {'AxisError': <class 'numpy.exceptions.AxisError'>, 'ComplexWarning': <class 'numpy.exceptions.ComplexWarning'>, 'Modu...ng': <class 'numpy.exceptions.ModuleDeprecationWarning'>, 'TooHardError': <class 'numpy.exceptions.TooHardError'>, ...}
        attrs_then = {'__cached__': '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__pycach...packages/numpy/__init__.py', '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, ...}
        attrs_updated = {}
        key        = '__cached__'
        loader_state = {'__class__': <class 'module'>, '__dict__': {'__cached__': '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/l...t 0x7f07a3e33c20>, ...}, 'is_loading': True, 'lock': <unlocked _thread.RLock object owner=0 count=0 at 0x7f07a3492740>}
        original_name = 'numpy'
        self       = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
        value      = '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__pycache__/__init__.cpython-313.pyc'
../../../../BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py:113: in <module>
    from . import version
        AxisError  = <class 'numpy.exceptions.AxisError'>
        ComplexWarning = <class 'numpy.exceptions.ComplexWarning'>
        ModuleDeprecationWarning = <class 'numpy.exceptions.ModuleDeprecationWarning'>
        TooHardError = <class 'numpy.exceptions.TooHardError'>
        VisibleDeprecationWarning = <class 'numpy.exceptions.VisibleDeprecationWarning'>
        _CopyMode  = <enum '_CopyMode'>
        _NoValue   = <no value>
        __builtins__ = <builtins>
        __cached__ = '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__pycache__/__init__.cpython-313.pyc'
        __doc__    = '\nNumPy\n=====\n\nProvides\n  1. An array object of arbitrary homogeneous items\n  2. Fast mathematical operations ov...en\navailable as array methods, i.e. ``x = np.array([1,2,3]); x.sort()``.\nExceptions to this rule are documented.\n\n'
        __file__   = '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'
        __loader__ = <_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>
        __name__   = 'numpy'
        __package__ = 'numpy'
        __path__   = ['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy']
        __spec__   = ModuleSpec(name='numpy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, origin='/build...ule_search_locations=['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy'])
        _globals   = <module 'numpy._globals' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/_globals.py'>
        _utils     = <module 'numpy._utils' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/_utils/__init__.py'>
        exceptions = <module 'numpy.exceptions' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/exceptions.py'>
        sys        = <module 'sys' (built-in)>
        warnings   = <module 'warnings' from '/usr/lib64/python3.13/warnings.py'>
<frozen importlib._bootstrap>:1412: in _handle_fromlist
    ???
        fromlist   = ('version',)
        import_    = <built-in function __import__>
        module     = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
        recursive  = False
        x          = 'version'
<frozen importlib.util>:209: in __getattribute__
    ???
        __dict__   = {'AxisError': <class 'numpy.exceptions.AxisError'>, 'ComplexWarning': <class 'numpy.exceptions.ComplexWarning'>, 'Modu...ng': <class 'numpy.exceptions.ModuleDeprecationWarning'>, 'TooHardError': <class 'numpy.exceptions.TooHardError'>, ...}
        __spec__   = ModuleSpec(name='numpy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, origin='/build...ule_search_locations=['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy'])
        attr       = 'version'
        attrs_now  = {'AxisError': <class 'numpy.exceptions.AxisError'>, 'ComplexWarning': <class 'numpy.exceptions.ComplexWarning'>, 'Modu...ng': <class 'numpy.exceptions.ModuleDeprecationWarning'>, 'TooHardError': <class 'numpy.exceptions.TooHardError'>, ...}
        attrs_then = {'__cached__': '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__pycach...packages/numpy/__init__.py', '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, ...}
        attrs_updated = {'AxisError': <class 'numpy.exceptions.AxisError'>, 'ComplexWarning': <class 'numpy.exceptions.ComplexWarning'>, 'Modu...ng': <class 'numpy.exceptions.ModuleDeprecationWarning'>, 'TooHardError': <class 'numpy.exceptions.TooHardError'>, ...}
        key        = 'AxisError'
        loader_state = {'__class__': <class 'module'>, '__dict__': {'__cached__': '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/l...t 0x7f07a3e33c20>, ...}, 'is_loading': True, 'lock': <unlocked _thread.RLock object owner=0 count=0 at 0x7f07a3492740>}
        original_name = 'numpy'
        self       = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
        value      = <class 'numpy.exceptions.AxisError'>
../../../../BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py:113: in <module>
    from . import version
        AxisError  = <class 'numpy.exceptions.AxisError'>
        ComplexWarning = <class 'numpy.exceptions.ComplexWarning'>
        ModuleDeprecationWarning = <class 'numpy.exceptions.ModuleDeprecationWarning'>
        TooHardError = <class 'numpy.exceptions.TooHardError'>
        VisibleDeprecationWarning = <class 'numpy.exceptions.VisibleDeprecationWarning'>
        _CopyMode  = <enum '_CopyMode'>
        _NoValue   = <no value>
        __builtins__ = <builtins>
        __cached__ = '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__pycache__/__init__.cpython-313.pyc'
        __doc__    = '\nNumPy\n=====\n\nProvides\n  1. An array object of arbitrary homogeneous items\n  2. Fast mathematical operations ov...en\navailable as array methods, i.e. ``x = np.array([1,2,3]); x.sort()``.\nExceptions to this rule are documented.\n\n'
        __file__   = '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'
        __loader__ = <_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>
        __name__   = 'numpy'
        __package__ = 'numpy'
        __path__   = ['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy']
        __spec__   = ModuleSpec(name='numpy', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f07a3e33c20>, origin='/build...ule_search_locations=['/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy'])
        _globals   = <module 'numpy._globals' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/_globals.py'>
        _utils     = <module 'numpy._utils' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/_utils/__init__.py'>
        exceptions = <module 'numpy.exceptions' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/exceptions.py'>
        sys        = <module 'sys' (built-in)>
        warnings   = <module 'warnings' from '/usr/lib64/python3.13/warnings.py'>
<frozen importlib._bootstrap>:1412: in _handle_fromlist
    ???
E   RecursionError: maximum recursion depth exceeded
        fromlist   = ('version',)
        import_    = <built-in function __import__>
        module     = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.26.4-2.fc41.x86_64/usr/lib64/python3.13/site-packages/numpy/__init__.py'>
        recursive  = False
        x          = 'version'
!!! Recursion detected (same locals & position)

Python and NumPy Versions:

Python 3.13.0a5, numpy 1.26.4 (from Fedora)

Runtime Environment:

No response

Context for the issue:

No response

@mattip
Copy link
Member

mattip commented Mar 20, 2024

What happens when you try to build and test HEAD or 2.0.0b1?

@befeleme
Copy link
Author

I attempted to build 2.0.0b1 as RPM but it was far from trivial and I didn't succeed. I was also not successful with building numpy locally, because not all of the dependencies are available for Python 3.13, so I can't really tell.

@rgommers
Copy link
Member

@tacaswell in your numpy main builds for Python 3.13, do you see this test failing?

@tacaswell
Copy link
Contributor

Yes I see this. I see a total of 9 errors [7 of which are undefined symbol: _PyErr_WriteUnraisableMsg, 1 of which is meson, and this] and 95 failures [that all look meson or f2py related].

Plus having to delete the numpy/distutils directory to get pytest to find the test without import errors.

@rgommers
Copy link
Member

Great, thanks. Then I guess we have to figure out if this test is not written in a future-proof way, or if it's a regression in importlib.

@hroncok
Copy link
Contributor

hroncok commented Mar 28, 2024

Likely related:

python/cpython#117178
python/cpython#117179

@ngoldbaum
Copy link
Member

For whatever reason the test passes on my mac.

@ngoldbaum
Copy link
Member

Ah it's because it was fixed upstream, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants