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


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

collecting variable assignments through settrace

Started byskunkwerk <skunkwerk@gmail.com>
First post2013-06-18 11:38 -0700
Last post2013-06-18 17:47 -0400
Articles 2 — 2 participants

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


Contents

  collecting variable assignments through settrace skunkwerk <skunkwerk@gmail.com> - 2013-06-18 11:38 -0700
    Re: collecting variable assignments through settrace Terry Reedy <tjreedy@udel.edu> - 2013-06-18 17:47 -0400

#48657 — collecting variable assignments through settrace

Fromskunkwerk <skunkwerk@gmail.com>
Date2013-06-18 11:38 -0700
Subjectcollecting variable assignments through settrace
Message-ID<0fd5f976-d22c-497d-b829-54ec881c3b6f@googlegroups.com>
Hi,
  I'm writing a custom profiler that uses sys.settrace.  I was wondering if there was any way of tracing the assignments of variables inside a function as its executed, without looking at locals() at every single line and comparing them to see if anything has changed.

Sort of like xdebug's collect_assignments parameter in PHP.

thanks,
imran

[toc] | [next] | [standalone]


#48671

FromTerry Reedy <tjreedy@udel.edu>
Date2013-06-18 17:47 -0400
Message-ID<mailman.3560.1371592076.3114.python-list@python.org>
In reply to#48657
On 6/18/2013 2:38 PM, skunkwerk wrote:
> Hi, I'm writing a custom profiler that uses sys.settrace.  I was
> wondering if there was any way of tracing the assignments of
> variables inside a function as its executed, without looking at
> locals() at every single line and comparing them to see if anything
> has changed.

The stdlib has an obscure module bdb (basic debugger) that is used in 
both pdb (python debugger) and idlelib.Debugger. The latter can display 
global and local variable names. I do not know if it does anything other 
than rereading globals() and locals(). It only works with a file loaded 
in the editor, so it potentially could read source lines to looks for 
name binding statements (=, def, class, import) and determine the names 
just bound. On the other hand, re-reading is probably fast enough for 
human interaction.

My impression from another issue is that traceing causes the locals dict 
to be updated with each line, so you do not actually have to have to 
call locals() with each line. However, that would mean you have to make 
copies to compare.

-- 
Terry Jan Reedy

[toc] | [prev] | [standalone]


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


csiph-web