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


Groups > comp.lang.python > #48671

Re: collecting variable assignments through settrace

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '(python': 0.07; 'class,': 0.07; 'variables': 0.07; 'latter': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'jan': 0.12; 'assignments': 0.16; 'bound.': 0.16; 'compare.': 0.16; 'dict': 0.16; 'editor,': 0.16; 'executed,': 0.16; 'pdb': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:variable': 0.16; 'tracing': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'module': 0.19; 'header:User- Agent:1': 0.23; 'comparing': 0.24; 'looks': 0.24; 'source': 0.25; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'wondering': 0.29; "i'm": 0.30; 'lines': 0.31; 'changed.': 0.31; 'names.': 0.31; 'obscure': 0.31; 'file': 0.32; 'probably': 0.32; 'another': 0.32; 'updated': 0.34; 'could': 0.34; 'display': 0.35; 'there': 0.35; 'impression': 0.36; 'hi,': 0.36; 'to:addr:python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'anything': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'read': 0.60; 'received:173': 0.61; 'name': 0.63; 'determine': 0.67; 'line,': 0.68; 'potentially': 0.81; 'interaction.': 0.84; 'received:fios.verizon.net': 0.84; 'hand,': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: collecting variable assignments through settrace
Date Tue, 18 Jun 2013 17:47:36 -0400
References <0fd5f976-d22c-497d-b829-54ec881c3b6f@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
In-Reply-To <0fd5f976-d22c-497d-b829-54ec881c3b6f@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3560.1371592076.3114.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371592076 news.xs4all.nl 15926 [2001:888:2000:d::a6]:37385
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:48671

Show key headers only | View raw


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

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


Thread

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

csiph-web