Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #57816

Re: Debugging decorator

Date 2013-10-28 13:43 +0100
From Schneider <js@globe.de>
Organization GLOBE Development GmbH
Subject Re: Debugging decorator
References <CAFEUn8YwMwB6m9LGqsXK8iijK_DRnwv88Xxp8VP_x=Hq2TUnhQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1697.1382964688.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Debugging decorator Schneider <js@globe.de> - 2013-10-28 13:43 +0100

csiph-web