Tracing the execution of scripts?

Michael B. Trausch mike$#at^&nospam!%trauschus
Fri Oct 27 08:34:28 EDT 2006


Stephan Kuhagen wrote:
> "Michael B. Trausch" <"mike$#at^&nospam!%trauschus"> wrote:
> 
>> Basically, is there something that will log every line of Python code
>> executed, in its order of execution, to a text file so that I can see
>> what is (or isn't) happening that I am expecting?
> 
> Python itself can do this for you. A __VERY__ simple approach:
> 
[snip]
> 
> Insert this in you program and you get a trace of every line of Python-Code
> executed in the file trace.txt. You must read the documentation of the
> module inspect and of sys.settrace() to understand, what happens and what
> it means. Additionally, if it should work with threads, you must take care
> that every thread gets its own output file. But as a first step to get a
> trace of execution, this should do it.
> 

I will need to keep this around to look at a little later.  It looks
like it would be something particularly useful when line-tracing by
itself fails.  I am constantly finding myself amazed at Python's
capabilities.

	-- Mike



More information about the Python-list mailing list