8000 Unbound Local Variable: parent deleted without ensuring it got created first · Issue #79 · scientific-python/lazy-loader · GitHub
[go: up one dir, main page]

Skip to content

Unbound Local Variable: parent deleted without ensuring it got created first #79

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

Closed
scnerd opened this issue Oct 14, 2023 · 2 comments
Closed

Comments

@scnerd
Copy link
scnerd commented Oct 14, 2023

Problem

I get the following stacktrace from librosa's usage of lazy_loader:

  File "C:\...\lib\site-packages\datasets\features\audio.py", line 194, in decode_example
    array = librosa.to_mono(array)
  File "C:\...\lib\site-packages\lazy_loader\__init__.py", line 78, in __getattr__
    attr = getattr(submod, name)
  File "C:\...\lib\site-packages\lazy_loader\__init__.py", line 77, in __getattr__
    submod = importlib.import_module(submod_path)
  File "C:\...\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\.\lib\site-packages\librosa\core\audio.py", line 31, in <module>
    samplerate = lazy.load("samplerate")
  File "C:\...\lib\site-packages\lazy_loader\__init__.py", line 203, in load
    del parent
UnboundLocalError: local variable 'parent' referenced before assignment

Here's the offending code block:

            try:
                parent = inspect.stack()[1]
                frame_data = {
                    "spec": fullname,
                    "filename": parent.filename,
                    "lineno": parent.lineno,
                    "function": parent.function,
                    "code_context": parent.code_context,
                }
                return DelayedImportErrorModule(frame_data, "DelayedImportErrorModule")
            finally:
                del parent

Environment

Python version: 3.10
lazy_loader version: 0.3

Solution

The assignment to parent should occur before the try block. Errors with the inspect.stack()[1] chunk should be handled in a separate try/except clause.

@stefanv
Copy link
Member
stefanv commented Jan 25, 2024

@scnerd Thanks for the report; could you verify whether this was addressed by #83

@stefanv
Copy link
Member
stefanv commented Mar 15, 2024

We have resolved two race conditions, and these fixes will be available in the next release of lazy_loader & Python.

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

No branches or pull requests

2 participants
0