Skip to content


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

yscumc opened this Issue · 8 comments

4 participants


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\", 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\", line 100, in process_request
  File "C:\Python27\lib\site-packages\django_debug_toolbar-0.9.4-py2.7.egg\debug_toolbar\panels\", 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

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.


Having the same issue on OSX..


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

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

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...


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


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


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


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.


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

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.