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


Groups > comp.lang.python > #57816 > unrolled thread

Re: Debugging decorator

Started bySchneider <js@globe.de>
First post2013-10-28 13:43 +0100
Last post2013-10-28 13:43 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#57816 — Re: Debugging decorator

FromSchneider <js@globe.de>
Date2013-10-28 13:43 +0100
SubjectRe: Debugging decorator
Message-ID<mailman.1697.1382964688.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web