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

Circular import when debug trace #1046

Closed
zhengxyz123 opened this issue Feb 11, 2024 · 6 comments
Closed

Circular import when debug trace #1046

zhengxyz123 opened this issue Feb 11, 2024 · 6 comments
Labels
bug Something isn't working reproducible Has example code which reproduces the issue

Comments

@zhengxyz123
Copy link
Contributor

When I run

PYGLET_DEBUG_TRACE=1 python ...

It raises

Traceback (most recent call last):
  File "<frozen runpy>", line 189, in _run_module_as_main
  File "<frozen runpy>", line 148, in _get_module_details
  File "<frozen runpy>", line 112, in _get_module_details
  File "/home/jason/Desktop/mystery/mystery/__init__.py", line 4, in <module>
    from pyglet import version as pyglet_ver
  File "/home/jason/Desktop/mystery/lib/python3.11/site-packages/pyglet/__init__.py", line 307, in <module>
    class _ModuleProxy:
  File "/home/jason/Desktop/mystery/lib/python3.11/site-packages/pyglet/__init__.py", line 307, in _ModuleProxy
    class _ModuleProxy:
    
  File "/home/jason/Desktop/mystery/lib/python3.11/site-packages/pyglet/__init__.py", line 307, in _ModuleProxy
    class _ModuleProxy:
    
  File "/home/jason/Desktop/mystery/lib/python3.11/site-packages/pyglet/__init__.py", line 277, in _trace_func
    _trace_frame(thread, frame, indent)
  File "/home/jason/Desktop/mystery/lib/python3.11/site-packages/pyglet/__init__.py", line 221, in _trace_frame
    from pyglet import lib
  File "/home/jason/Desktop/mystery/lib/python3.11/site-packages/pyglet/lib.py", line 21, in <module>
    script_path = pyglet.resource.get_script_home()
                  ^^^^^^^^^^^^^^^
AttributeError: partially initialized module 'pyglet' has no attribute 'resource' (most likely due to a circular import)

Maybe a circular import happened(in pyglet 2.0.10).

@zhengxyz123 zhengxyz123 added the bug Something isn't working label Feb 11, 2024
@benmoran56
Copy link
Member

Can you try removing that import, and copying the get_script_home function directly into the lib module?

@zhengxyz123
Copy link
Contributor Author

I have found an easier way by replacing this line

import pyglet

with

13 import pyglet
14 import pyglet.resource

@benmoran56 benmoran56 added the reproducible Has example code which reproduces the issue label Feb 14, 2024
@benmoran56
Copy link
Member

If you put pyglet.options['debug_trace'] = True in the top of your program, that does work OK.

Your solution also works, but it lead me to the root issue:
In pyglet.__init__, we are calling the _install_trace() function before we set up the ModuleProxy code. That means the pyglet.resource module doesn't exist yet 😅

I'll try to rearrange those.

@benmoran56
Copy link
Member

Can you give it a try with the latest code in master?

@zhengxyz123
Copy link
Contributor Author

There is no problem when I run

PYGLET_DEBUG_TRACE=1 python3

then import pyglet.

@benmoran56
Copy link
Member

Great! Thanks for testing. We can close this I think. It will be in the next release (hopefully soon).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproducible Has example code which reproduces the issue
Projects
None yet
Development

No branches or pull requests

2 participants