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

module 'resource' has no attribute 'getrusage' #2023

Open
softquantum opened this issue Oct 30, 2024 · 11 comments
Open

module 'resource' has no attribute 'getrusage' #2023

softquantum opened this issue Oct 30, 2024 · 11 comments

Comments

@softquantum
Copy link

Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 5.1.2
Wagtail version: 6.3.rc2
Exception Type: AttributeError
Exception Value:

module 'resource' has no attribute 'getrusage'

Exception Location: /Users/.../Code/wagtail/project/.venv/lib/python3.13/site-packages/debug_toolbar/panels/timer.py, line 64, in process_request
Raised during: wagtail.views.serve

Maybe due to wagtail but posting here if other have the issue with python 3.13. I will update if I can narrow down the problem or if due to wagtail.

@tim-schilling
Copy link
Member

Do you have a file in your project named resource?

@softquantum
Copy link
Author

I have an app in my project named resource yes.

I just realized my MacOS updated to Sequoia 15.1. I have updated my dev.py settings by disabling debug_toolbar.panels.timer.TimerPanel. The debug toolbar is running now (less 1 panel)

DEBUG_TOOLBAR_PANELS = [
'debug_toolbar.panels.versions.VersionsPanel',
'debug_toolbar.panels.settings.SettingsPanel',
'debug_toolbar.panels.headers.HeadersPanel',
'debug_toolbar.panels.request.RequestPanel',
'debug_toolbar.panels.sql.SQLPanel',
'debug_toolbar.panels.staticfiles.StaticFilesPanel',
'debug_toolbar.panels.templates.TemplatesPanel',
'debug_toolbar.panels.cache.CachePanel',
'debug_toolbar.panels.signals.SignalsPanel',
'debug_toolbar.panels.logging.LoggingPanel',
'debug_toolbar.panels.redirects.RedirectsPanel',
# 'debug_toolbar.panels.timer.TimerPanel', # Not working since MacOS Sequoia (15.1)
]

@tim-schilling
Copy link
Member

My guess is that the toolbar is importing your resource package rather than the stdlib resource. I'm pretty confident, but only you can determine that for sure.

@softquantum
Copy link
Author

softquantum commented Oct 30, 2024

You are correct. The behaviour of accessing the system-level resource has been changed I guess from Sequoia 15.0 to 15.1. This is the only difference between my yesterday's working config to today's not working. (I will not reinstall my Mac from scratch to test if this is the same on a fresh install 😆)

If there are more complaining about this, we may want to update the doc or have a fall back in place. Happy to help. (and I will make a personal note to not call a module or app 'resource')

@softquantum
Copy link
Author

Thank you for your help!

@tim-schilling
Copy link
Member

I think the better approach is to have a namespace for your projects packages to avoid the conflict. So you would have from myproject.resource import something

I'm going to close this issue though. I don't feel like it's something we should warn about in the docs because we'd have to warn about every stdlib arguably.

@softquantum
Copy link
Author

That is what my project had already 'from myproject.resource import ...', not sure to understand the sequence of events then. Anyway, will test further when I have some spare time. thank you.

@tim-schilling
Copy link
Member

Oh, weird. Then this may be a bug with sequoia. Can you run that missing function in a normal python shell?

@tim-schilling tim-schilling reopened this Oct 30, 2024
@softquantum
Copy link
Author

It is just a simple app within my wagtail project that has 2 models and a viewset to manage resources (documents) with some additional fields. I will do more search on this as I want to understand.

@softquantum
Copy link
Author

I leave this track here for later. It shows the namespace is not the same. I will dig further on a fresh project and see if I can reproduce on my Mac (this is not happening on Linux)

Shell Plus Django Imports

from django.core.cache import cache
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import transaction
from django.db.models import Avg, Case, Count, F, Max, Min, Prefetch, Q, Sum, When
from django.utils import timezone
from django.urls import reverse
from django.db.models import Exists, OuterRef, Subquery
Python 3.13.0 (main, Oct 11 2024, 14:16:13) [Clang 19.1.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)

import sys
print([name for name in sys.modules if 'resource' in name])
['myproject.resource', 'importlib.resources.abc', 'importlib.resources._common', 'importlib.resources._functional', 'importlib.resources', 'importlib.resources._adapters', 'importlib.resources._itertools', 'importlib.resources.readers', 'myproject.resource.forms', 'myproject.resource.models.document', 'myproject.resource.models.resource', 'myproject.resource.models', 'resource']
import resource
resource.get
resource.getpagesize() resource.getrlimit( resource.getrusage(

@tim-schilling
Copy link
Member

You could add some code the to installed toolbar on your end to inspect what resource is at /Users/.../Code/wagtail/project/.venv/lib/python3.13/site-packages/debug_toolbar/panels/timer.py, line 64, in process_request

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