homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eli.bendersky
Recipients eli.bendersky
Date 2010年07月21日.14:30:30
SpamBayes Score 4.3577206e-08
Marked as misclassified No
Message-id <1279722632.82.0.584454979643.issue9323@psf.upfronthosting.co.za>
In-reply-to
Content
[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.
History
Date User Action Args
2010年07月21日 14:30:33eli.benderskysetrecipients: + eli.bendersky
2010年07月21日 14:30:32eli.benderskysetmessageid: <1279722632.82.0.584454979643.issue9323@psf.upfronthosting.co.za>
2010年07月21日 14:30:31eli.benderskylinkissue9323 messages
2010年07月21日 14:30:30eli.benderskycreate

AltStyle によって変換されたページ (->オリジナル) /