New submission from Eli Bendersky <eli...@gmail.com>: [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. ---------- files: traceme.py messages: 111066 nosy: eli.bendersky priority: normal severity: normal status: open title: trace.py bug with the main file being traced type: behavior versions: Python 3.1, Python 3.2 Added file: http://bugs.python.org/file18105/traceme.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue9323> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com