Is there a way to debug a function that is dynamically determined at runtime?
Or at least is there an easy way to find out where this function is created?
Refresh to get more details:
I used the inspect module:
ipdb> inspect.getmodule(im.get_thumbnail_url) Out[0]: <module 'django.utils.functional' from 'C:\java\python\Python25\Lib\site -packages\django\utils\functional.pyc'> ipdb> inspect.getsource(im.get_thumbnail_url) Out[0]: ' def _curried(*moreargs, **morekwargs):\n return _curried_fun c(*(args+moreargs), **dict(kwargs, **morekwargs))\n'
Here inspect shows that the get_thumbnail_url method of the get_thumbnail_url class for pinax is created by the django.utils.functional.curry._curried function. But it still does not show where the method is created, namely, where the _curried function is _curried . This information is needed to find out how get_thumbnail_url is implemented.
I can put pdb inside _curried , but then it breaks many times because it is a very often used function call. I need to have some distinguishing feature to use a breakpoint condition.
Solution Update:
Thanks for all the suggestions. I have found a solution. Let me explain how I found this. Maybe this will help other people:
First I searched for the term 'get_thumbnail_url' in the pinax source code. To no avail. Secondly, I searched for the term "thumbnail" in the pinax source code. There is no useful result. Finally, I searched for the term "curry" in the pinax source code. Below was one of several results:
def add_accessor_methods(self, *args, **kwargs): for size in PhotoSizeCache().sizes.keys(): setattr(self, 'get_%s_size' % size, curry(self._get_SIZE_size, size=size)) setattr(self, 'get_%s_photosize' % size, curry(self._get_SIZE_photosize, size=size)) setattr(self, 'get_%s_url' % size, curry(self._get_SIZE_url, size=size)) setattr(self, 'get_%s_filename' % size, curry(self._get_SIZE_filename, size=size))
get_thumbnail_url this call is made: curry(self._get_SIZE_url, size=size)) .
But of course, this is not a general solution method. If you can share alternative ways to find out where the dynamically defined function is actually created, this will be very helpful.
Edit:
The best overall solution is written below by Jason Orendorf.