[Assorted-commits] SF.net SVN: assorted: [248] python-commons/trunk/src/commons/startup.py
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-01-20 06:25:26
|
Revision: 248 http://assorted.svn.sourceforge.net/assorted/?rev=248&view=rev Author: yangzhang Date: 2008-01-19 22:25:30 -0800 (Sat, 19 Jan 2008) Log Message: ----------- added better profiling facility, made consistent with multithreaded facility; removed is_environ_set Modified Paths: -------------- python-commons/trunk/src/commons/startup.py Modified: python-commons/trunk/src/commons/startup.py =================================================================== --- python-commons/trunk/src/commons/startup.py 2008-01-20 00:27:16 UTC (rev 247) +++ python-commons/trunk/src/commons/startup.py 2008-01-20 06:25:30 UTC (rev 248) @@ -7,9 +7,10 @@ from __future__ import absolute_import from .log import ( critical, debug, config_logging ) -from .environ import ( is_environ_set, get_environs ) +from .environ import ( get_environs ) from .interp import interp from sys import _current_frames +from threading import currentThread import os, sys class UnsetError( Exception ): pass @@ -145,21 +146,26 @@ runner = ( ( lambda main, args: main( args ) ) if runner is None else runner ) main = frame.f_globals[ 'main' ] if main is None else main - do_debug = is_environ_set( 'PYDBG' ) - do_profile = is_environ_set( 'PYPROF' ) + do_debug = os.environ.get( 'PYDBG', '' ) != '' + do_profile = os.environ.get( 'PYPROF', '' ) != '' if do_debug: import pdb signal(SIGINT, lambda *args: pdb.set_trace()) status = pdb.runcall( runner, main, sys.argv ) elif do_profile: - import cProfile as profile - container = {} - output_path = os.environ[ 'PYPROF' ] - profile.runctx( - 'container[ "status" ] = runner( main, sys.argv )', - globals(), locals(), filename = output_path ) - status = container[ 'status' ] + from cProfile import runctx + container = [] + try: + outpath = os.environ[ 'PYPROF' ] % \ + currentThread().getName() + except: + error( 'bad PYPROF:', os.environ[ 'PYPROF' ] ) + status = runner( main, sys.argv ) + else: + runctx( 'container[0] = runner( main, sys.argv )', + globals(), locals(), filename = outpath ) + status = container[0] else: status = runner( main, sys.argv ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |