Title: trace module borks __file__
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 2.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, zseil
Priority: normal Keywords:

Created on 2007-03-28 19:05 by skip.montanaro, last changed 2010-08-01 08:35 by georg.brandl. This issue is now closed.

File name Uploaded Description Edit
trace.diff skip.montanaro, 2007-03-28 20:38
Messages (5)
msg31671 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2007-03-28 19:05
Stick this in a file (say,

    print __file__

If I run it as "python" using Python 2.4, 2.5 or 2.6 it prints as expected, e.g.:

    % python ~/tmp/

If, however, I run it under control of the trace module I get something entirely different:

    % python -m trace --count ~/tmp/
    % python -m trace --trace ~/tmp/
     --- modulename: threading, funcname: settrace     _trace_hook = func
     --- modulename: trace, funcname: <module>
    <string>(1):   --- modulename: trace, funcname: <module> print __file__

Definitely looks buggy to me...
msg31672 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2007-03-28 20:01
I believe this is because the trace module calls execfile()
to run the file.  I'm not sure if there's an easy fix for
this problem.
msg31673 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2007-03-28 20:38
Hmmm...  Maybe not so hard after all.  See attached diff.  Does anyone see a problem with simply overwriting the trace module's __file__ attribute?

File Added: trace.diff
msg31674 - (view) Author: Ziga Seilnacht (zseil) * (Python committer) Date: 2007-04-15 18:39
Wouldn't it be better for trace.main() to call
Tracer.runctx() instead of  That
way you could use a copy of __main__.__dict__
for locals and globals and overwrite the filename
there.  Note that your solution would still report
the wrong filename if someone called tracer.main()
from his own main script.
msg112290 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-08-01 08:35
Fixed in r83393 with explicit globals that also specify __name__.
Date User Action Args
2010-08-01 08:35:48georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112290

resolution: fixed
2010-05-20 20:28:24skip.montanarosetnosy: - skip.montanaro
2009-03-30 17:04:26ajaksu2setstage: test needed
type: behavior
versions: + Python 2.6
2007-03-28 19:05:03skip.montanarocreate