Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Doesn't work with Django's SimpleLazyObject #92

valtron opened this Issue · 4 comments

4 participants


I'm using pycallgraph 0.5.1, Django 1.3.1, Python 2.7.2 32bit.

Line 235 of, which gets the "__class__" of "self" in the current call being traced, causes an infinite loop. The method being traced is SimpleLazyObject's "__init__", which among other things sets "self._wrapped". ".__class__" triggers the "__get_class" method on the object, which checks if "_wrapped" is None, but since the constructor hasn't run yet (it was intercepted by the tracer), this gets translated into a "__getattr__" call on the object, which again checks if "_wrapped" is None... etc.

Here is the relevant part the stack trace. I used custom middleware to integrate pycallgraph in Django.

C:\Python27\lib\site-packages\django\contrib\auth\ in auth
  57. 'user': SimpleLazyObject(get_user),
C:\Python27\lib\site-packages\django\utils\ in __init__
  316. def __init__(self, func):
C:\Python27\lib\site-packages\ in tracer
  235. class_name = frame.f_locals['self'].__class__.__name__
C:\Python27\lib\site-packages\django\utils\ in __get_class
  354. if self._wrapped is None: self._setup()
C:\Python27\lib\site-packages\django\utils\ in __getattr__
  275. if self._wrapped is None:
... (this is the infinite loop) ...
C:\Python27\lib\site-packages\django\utils\ in __getattr__
  275. if self._wrapped is None:


Same issue on django 1.4.2
For anyone interested in using pycallgraph to profile a django app, I did some debugging and solved this.
Add the following:

_wrapped = None


I'll make a pull request upstream once I get some time to write tests, explain this, etc.


This bug will be fixed in Django 1.6.

gak commented

OK great. Closing.

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