Message111066
[This bug was discovered by Alexander Belopolsky, during the work on Issue 9317]
Bug report
**********
The attached traceme.py file demonstrates the following problem:
With python 2.7:
$ python2 -m trace -c -s traceme.py
lines cov% module (path)
1 100% threading (Lib/threading.py)
6 100% traceme (traceme.py)
The first entry is clearly spurious, but traceme looks right. With py3k, however, I get
$ python3 -m trace -c -s traceme.py
lines cov% module (path)
1 100% threading (Lib/threading.py)
No traceme line at all.
Analysis
********
When trace.py actually runs the script, it uses this code in 3.x:
t.run('exec(%r)' % (script,))
instead of this code in 2.x:
t.run('execfile(%r)' % (progname,))
`exec` doesn't have the program name to attach to the code object created, and calls it '<string>' by default. However, this file name is ignored by the trace module.
`execfile` doesn't exist in 3.x, so an alternative approach is needed.
Proposed solution
*****************
Instead of t.run as displayed above, use this code:
with open(progname) as fp:
code = compile(fp.read(), progname, 'exec')
t.run(code)
The code object created by `compile` attaches the program name and is executable by t.run (because t.run actually calls `exec` which can run the result of `compile`).
This solution fixes the problem:
$ py3d -m trace -c -s traceme.py
lines cov% module (path)
1 100% threading (/home/eliben/python_src/eliben-py3k/Lib/threading.py)
6 100% traceme (traceme.py)
I'll attach a patch file that was creates vs. the latest trunk, with this fix. |
|
Date |
User |
Action |
Args |
2010-07-21 14:30:33 | eli.bendersky | set | recipients:
+ eli.bendersky |
2010-07-21 14:30:32 | eli.bendersky | set | messageid: <1279722632.82.0.584454979643.issue9323@psf.upfronthosting.co.za> |
2010-07-21 14:30:31 | eli.bendersky | link | issue9323 messages |
2010-07-21 14:30:30 | eli.bendersky | create | |
|