profiling setuptools console scripts
This is very minor, but I recently ran across a case where I wanted to profile some code invoked that is invoked by a setuptools console_script. The generated script is in the form: sys.exit( load_entry_point('supervisor==3.0a2', 'console_scripts', 'supervisord')() ) Due to the explicit sys.exit() call, I could not (or at least could not figure out how to) place the profiling hair in the invoked code. I wound up having to change the script to look like this: cmd = "load_entry_point ('supervisor==3.0a2','console_scripts','supervisord')()" if os.environ.has_key('SUPERVISOR_PROFILE'): import profile import pstats profile.runctx(cmd, globals(), locals(), '/tmp/superprofile') stats = pstats.Stats('/tmp/superprofile') stats.strip_dirs() stats.sort_stats('cumulative', 'calls', 'time') stats.print_stats(.3) else: sys.exit(eval(cmd)) I'm wondering if the default generated console_script should refrain from explicitly calling sys.exit. What a wonderful thing setuptools is, seriously. I'm really enjoying using it. - C
At 01:03 PM 9/5/2007 -0400, Chris McDonough wrote:
This is very minor, but I recently ran across a case where I wanted to profile some code invoked that is invoked by a setuptools console_script. The generated script is in the form:
sys.exit( load_entry_point('supervisor==3.0a2', 'console_scripts', 'supervisord')() )
Due to the explicit sys.exit() call, I could not (or at least could not figure out how to) place the profiling hair in the invoked code.
Why not just change the entry point to refer to your profiling function?
On Sep 5, 2007, at 1:52 PM, Phillip J. Eby wrote:
At 01:03 PM 9/5/2007 -0400, Chris McDonough wrote:
This is very minor, but I recently ran across a case where I wanted to profile some code invoked that is invoked by a setuptools console_script. The generated script is in the form:
sys.exit( load_entry_point('supervisor==3.0a2', 'console_scripts', 'supervisord')() )
Due to the explicit sys.exit() call, I could not (or at least could not figure out how to) place the profiling hair in the invoked code.
Why not just change the entry point to refer to your profiling function?
That works great. - C
participants (2)
-
Chris McDonough
-
Phillip J. Eby