Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 529047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:03:02+00:00 2026-05-13T09:03:02+00:00

Is there a way to debug a function that is defined dynamically in run

  • 0

Is there a way to debug a function that is defined dynamically in run time?

Or at least is there an easy way to find out where this function is produced?

Update to give more detail:

I used 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 photos.models.Image class of pinax is produced by django.utils.functional.curry._curried function. But it still doesn’t show where the method is produced, namely where is _curried function called. This information is necessary to find out how get_thumbnail_url is implemented.

I can put pdb inside _curried function, but then it breaks lots of times there because this is a very frequently used function call. I need to have some distinguishing feature to use breakpoint condition.

Update about solution:

Thanks for all suggestions. I found out the solution. Let me explain how I found it. Maybe it will help other people:

First, I searched for ‘get_thumbnail_url’ term in pinax source code. No result.
Second, I searched for ‘thumbnail’ term in pinax source code. No useful result.
Lastly, I searched for ‘curry’ term in pinax source code. The following 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 method is produced by this call: 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 a dynamically defined function is actually produced, this would be of great use.

Edit:

The best general solution is written below by Jason Orendorff.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:03:02+00:00Added an answer on May 13, 2026 at 9:03 am

    Given a function f, in CPython you can print f.func_code.co_filename and f.func_code.co_firstlineno to get the file and first line number. This will not help if the function was created using eval or exec.

    Tracebacks contain file and line information too.

    If you import dis you can use dis.dis(f) to see the CPython bytecodes; this might not be useful, but it might show some strings that help you find your way to the right place.

    Another thing to look at is PDB, the Python text-mode debugger. After an exception, import pdb; pdb.pm() launches PDB. It’s primitive, but useful; type help for a list of commands. where shows the stack.

    EDIT: You mention this is a curried function. If it was created using functools.partial, then it has a .func attribute that refers to the underlying function.

    EDIT 2: The general way would be to set a breakpoint on im.get_thumbnail_url and then immediately call it. Your breakpoint should hit right away. Then step until you reach the code you’re interested in.

    Since the curried function was, in this case, produced by code like:

    def curry(_curried_func,  *args,  **kwargs):
        def _curried(*moreargs, **morekwargs):
            return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
        return _curried
    

    another approach is to examine f.func_closure, like this:

    >>> f
    <function _curried at 0xb77d64fc>
    >>> f.func_closure
    (<cell at 0xb77eb44c: tuple object at 0xb77dfa0c>, <cell at 0xb77eb5e4: dict object at 0xb77d93e4>, <cell at 0xb77eb5cc: function object at 0xb77d1d84>)
    

    The function closes on three variables: a tuple, a dict, and a function. Obviously the function is the one we’re interested in (but fyi these three cells correspond to the variables args, kwargs, and _curried_func that are defined in the enclosing function curry but used by the closure _curried).

    >>> f.func_closure[2].cell_contents
    <function say at 0xb77d1d84>
    >>> import inspect
    >>> inspect.getsource(_)
    'def say(x):\n    print x\n'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You probably want to call setlocale() first, "LC_ALL" should do… May 14, 2026 at 9:06 am
  • Editorial Team
    Editorial Team added an answer Linux Ubuntu Desktop Jaunty Firebug FireCookie Pixel Perfect Web developer… May 14, 2026 at 9:06 am
  • Editorial Team
    Editorial Team added an answer Your code should look like this: var par = [];… May 14, 2026 at 9:06 am

Related Questions

I'm am trying to debug a DLL which is called from a VC++ application,
I am doing some work to track down a perceived bug in a git
I have a stored function in MySQL: CREATE FUNCTION `login_count`(o INT, start_date DATE, end_date
In trying to learn how to create objects in ActionScript, I have had no
I can easily set breakpoints in embedded JS functions, but I don't see any

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.