collecting variable assignments through settrace

S

skunkwerk

Hi,
I'm writing a custom profiler that uses sys.settrace. I was wondering ifthere 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
 
T

Terry Reedy

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top