Re: Debugging decorator

Discussion in 'Python' started by Schneider, Oct 28, 2013.

  1. Schneider

    Schneider Guest

    On 10/26/2013 01:55 AM, Yaşar Arabacı wrote:
    > Hi people,
    >
    > I wrote this decorator: https://gist.github.com/yasar11732/7163528
    >
    > When this code executes:
    >
    > @debugging
    > def myfunc(a, b, c, d = 48):
    > a = 129
    > return a + b
    >
    > print myfunc(12,15,17)
    >
    > This is printed:
    >
    > function myfunc called
    > a 12
    > c 17
    > b 15
    > d 48
    > assigned new value to a: 129
    > returning 144
    > 144
    >
    > I think I can be used instead of inserting and deleting print
    > statements when trying to see what is
    > passed to a function and what is assingned to what etc. I think it can
    > be helpful during debugging.
    >
    > It works by rewriting ast of the function and inserting print nodes in it.
    >
    > What do you think?
    >
    >


    Looks very nice, but I've three questions:

    1. What happens, if a function has more then one decorator? Wouldn't it
    be better to
    just remove the debugging decorator instead of removing all decorators?

    2. In the case of an assignment (but holds for the return statement too).
    think about the following code:

    a = 0
    @debugging
    def foo():
    a = a + 1

    def bar():
    #assign something else to a

    Imagine foo() and bar() being called in two different threads. Wouldn't
    it be better

    to replace a = a + 1 by

    |global_debugging_lock_objekt.acquire()|
    a = a + 1
    print "assigned new value to a, %r", a
    |global_debugging_lock_objekt.release()|

    for some global lock object.

    3. What happens in the case of a += 1?

    bg,
    Johannes

    --
    GLOBE Development GmbH
    Königsberger Strasse 260
    48157 MünsterGLOBE Development GmbH
    Königsberger Strasse 260
    48157 Münster
    0251/5205 390
     
    Schneider, Oct 28, 2013
    #1
    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. glomde
    Replies:
    5
    Views:
    525
    glomde
    Mar 29, 2007
  2. Yaþar Arabacý

    Debugging decorator

    Yaþar Arabacý, Oct 26, 2013, in forum: Python
    Replies:
    0
    Views:
    76
    Yaþar Arabacý
    Oct 26, 2013
  3. Chris Angelico

    Re: Debugging decorator

    Chris Angelico, Oct 26, 2013, in forum: Python
    Replies:
    0
    Views:
    104
    Chris Angelico
    Oct 26, 2013
  4. Eric S. Johansson

    Re: Debugging decorator

    Eric S. Johansson, Oct 27, 2013, in forum: Python
    Replies:
    0
    Views:
    103
    Eric S. Johansson
    Oct 27, 2013
  5. Chris Angelico

    Re: Debugging decorator

    Chris Angelico, Oct 28, 2013, in forum: Python
    Replies:
    0
    Views:
    81
    Chris Angelico
    Oct 28, 2013
Loading...

Share This Page