Having dont_inherit=0 as default in the call to compile() causes the compiled code to be parsed with from __future__ import print_function active, since this is used in pprofile.py. This results in syntax errors if the profiled script uses old non-function print statements:
$ cat tst.py
print "Hello world"
$ pprofile tst.py
Command line: ['tst.py']
Total duration: 0s
Traceback (most recent call last):
File "/home/stephan/.local/bin/pprofile", line 9, in <module>
load_entry_point('pprofile==1.9', 'console_scripts', 'pprofile')()
File "/home/stephan/.local/lib/python2.7/site-packages/pprofile.py", line 974, in main
runner.runpath(options.script, args)
File "/home/stephan/.local/lib/python2.7/site-packages/pprofile.py", line 555, in runpath
return self.runfile(open(path, 'rb'), argv, fd_name=path)
File "/home/stephan/.local/lib/python2.7/site-packages/pprofile.py", line 539, in runfile
dont_inherit=dont_inherit)
File "tst.py", line 2
print "Hello world"
^
SyntaxError: invalid syntax
Applying the __future__ imports from pprofile.py to the profiled code doesn't seem useful. Having dont_inherit=1, avoiding that issue, seems to be the better default. With this change the above test script can be profiled without errors.
Having
dont_inherit=0
as default in the call tocompile()
causes the compiled code to be parsed withfrom __future__ import print_function
active, since this is used inpprofile.py
. This results in syntax errors if the profiled script uses old non-functionprint
statements:Applying the
__future__
imports frompprofile.py
to the profiled code doesn't seem useful. Havingdont_inherit=1
, avoiding that issue, seems to be the better default. With this change the above test script can be profiled without errors.