Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

AttributeError: 'module' object has no attribute 'getrusage' #370

Closed
yscumc opened this Issue · 8 comments

4 participants

@yscumc

I get the following error during page load:

Internal Server Error: /
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 92, in get_response
    response = middleware_method(request)
  File "C:\Python27\lib\site-packages\django_debug_toolbar-0.9.4-py2.7.egg\debug_toolbar\middleware.py", line 100, in process_request
    panel.process_request(request)
  File "C:\Python27\lib\site-packages\django_debug_toolbar-0.9.4-py2.7.egg\debug_toolbar\panels\timer.py", line 30, in process_request
    self._start_rusage = resource.getrusage(resource.RUSAGE_SELF)
AttributeError: 'module' object has no attribute 'getrusage'
[03/Apr/2013 13:11:08] "GET / HTTP/1.1" 500 62374

Using:
Windows 7
Django (1.5)
django-debug-toolbar (0.9.4) - commit 6f79f0b
django-session-security (2.0.3)
Genshi (0.7)
MySQL-python (1.2.4b4)
pep8 (1.4.5)
pytz (2013b)
pywin32 (218)
selenium (2.31.0)
Trac (1.0.1)
tracaccountmanager (0.4.3)
unittest-data-provider (1.0.0)

Also doesn't work on the 0.9.4 release... that's why I took the latest from the repo.

@leesolway

Having the same issue on OSX..

@yscumc

FYI, my work-around was to disable debug_toolbar.panels.timer.TimerDebugPanel. This was my setting for DEBUG_TOOLBAR_PANELS:

DEBUG_TOOLBAR_PANELS = (
    'debug_toolbar.panels.version.VersionDebugPanel',
    # Throwing AttributeError: 'module' object has no attribute 'getrusage'
    #'debug_toolbar.panels.timer.TimerDebugPanel',
    'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
    'debug_toolbar.panels.headers.HeaderDebugPanel',
    'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
    'debug_toolbar.panels.template.TemplateDebugPanel',
    'debug_toolbar.panels.sql.SQLDebugPanel',
    'debug_toolbar.panels.signals.SignalDebugPanel',
    'debug_toolbar.panels.logger.LoggingPanel',
)

Hope this helps. The downside of course is that there's no timing functionality, but at least the other functionalities work. It would be nice if there was a real fix...

@leesolway

Thanks for the reply, i 'resolved' the issue in the same way.
Hopefully posting will help support people in finding the cause :).

@yscumc

Agreed, I'm sure there are others with the same problem, thanks for posting.

@bnekolny

One thing worth asking, do you happen to have another module named resource that is being imported instead of the standard lib resource?

@yscumc

Ah yes I have a django application with the package "resource". Now it makes sense... thanks for pointing that out! I haven't tried removing it yet as it's being used, but I'm sure that's likely the problem.

@aaugustin
Owner

The resource module is only available on Unix, hence the problem on Windows (regardless of the shadowing issue discussed above). At least two solutions could work:

  • write an alternative implementation for Windows
  • check if resource.getrusage exists, and if it doesn't, provide less information in the panel
  • check if resource.getrusage exists, and if it doesn't, raise a clear exception message
@aaugustin
Owner

In fact the code already deals with the case when the resource module doesn't exist.

I believe all the errors above are caused by shadowing the stdlib resource module with a local module.

It's a Python gotcha and there's not much we can do about it.

@aaugustin aaugustin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.