Hooking any/all 'calls'

Discussion in 'Python' started by Kevin Little, Dec 28, 2006.

  1. Kevin Little

    Kevin Little Guest

    In Python 2.4 or 2.5, what is the easiest way to hook any and all
    callables such that designated code is executed at the very start and
    end of each call? (Yes, I'm trying to come up with a little debugging
    tool!:) Is there a single metaclass who's "__call__" method can be
    wrapped to do this?

    TIA,
    -k
    Kevin Little, Dec 28, 2006
    #1
    1. Advertising

  2. At Wednesday 27/12/2006 23:07, Kevin Little wrote:

    >In Python 2.4 or 2.5, what is the easiest way to hook any and all
    >callables such that designated code is executed at the very start and
    >end of each call? (Yes, I'm trying to come up with a little debugging
    >tool!:) Is there a single metaclass who's "__call__" method can be
    >wrapped to do this?


    See Stain Soiland's site http://soiland.no/software/decorator for his
    logging decorator and logging metaclass.


    --
    Gabriel Genellina
    Softlab SRL






    __________________________________________________
    Preguntá. Respondé. Descubrí.
    Todo lo que querías saber, y lo que ni imaginabas,
    está en Yahoo! Respuestas (Beta).
    ¡Probalo ya!
    http://www.yahoo.com.ar/respuestas
    Gabriel Genellina, Dec 28, 2006
    #2
    1. Advertising

  3. Kevin Little

    fumanchu Guest

    Kevin Little wrote:
    > In Python 2.4 or 2.5, what is the easiest way to hook any and all
    > callables such that designated code is executed at the very start and
    > end of each call? (Yes, I'm trying to come up with a little debugging
    > tool!:) Is there a single metaclass who's "__call__" method can be
    > wrapped to do this?


    You probably want sys.settrace, which is specifically designed for
    creating debuggers, and is the basis for pdb, the debugger in the
    standard library. See
    http://docs.python.org/lib/module-sys.html#l2h-5159

    Feel free also to look through my own debugging aid (for clues on how
    to implement your own, or just to use for your needs):
    http://projects.amor.org/misc/wiki/PyConquer


    Robert Brewer
    System Architect
    Amor Ministries
    fumanchu, Dec 28, 2006
    #3
  4. Kevin Little

    Kevin Little Guest

    Thanks, Robert! That was exactly what I was looking for.
    -k

    "fumanchu" <> wrote:
    >Kevin Little wrote:
    >> In Python 2.4 or 2.5, what is the easiest way to hook any and all
    >> callables such that designated code is executed at the very start and
    >> end of each call? (Yes, I'm trying to come up with a little debugging
    >> tool!:) Is there a single metaclass who's "__call__" method can be
    >> wrapped to do this?

    >
    >You probably want sys.settrace, which is specifically designed for
    >creating debuggers, and is the basis for pdb, the debugger in the
    >standard library. See
    >http://docs.python.org/lib/module-sys.html#l2h-5159
    >
    >Feel free also to look through my own debugging aid (for clues on how
    >to implement your own, or just to use for your needs):
    >http://projects.amor.org/misc/wiki/PyConquer
    >
    >
    >Robert Brewer
    >System Architect
    >Amor Ministries
    >
    Kevin Little, Dec 28, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raja
    Replies:
    1
    Views:
    386
    Gabriele G. Ponti
    Jan 21, 2004
  2. Honne Gowda A
    Replies:
    2
    Views:
    856
    Karl Heinz Buchegger
    Oct 31, 2003
  3. andy6
    Replies:
    2
    Views:
    746
    andy6 via DotNetMonster.com
    Jun 9, 2006
  4. Richard Tobin
    Replies:
    24
    Views:
    766
  5. Bob
    Replies:
    5
    Views:
    246
Loading...

Share This Page