[Assorted-commits] SF.net SVN: assorted: [888] python-commons/trunk/src/commons/startup.py
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-07-13 19:20:52
|
Revision: 888 http://assorted.svn.sourceforge.net/assorted/?rev=888&view=rev Author: yangzhang Date: 2008-07-13 12:21:00 -0700 (Sun, 13 Jul 2008) Log Message: ----------- added command_name(); added handle_exceptions to startup() 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-07-13 18:47:55 UTC (rev 887) +++ python-commons/trunk/src/commons/startup.py 2008-07-13 19:21:00 UTC (rev 888) @@ -9,6 +9,7 @@ from .log import ( critical, debug, config_logging ) from .environ import ( get_environs ) from .interp import interp +from os.path import basename from sys import _current_frames from threading import currentThread import os, sys @@ -113,8 +114,11 @@ sys.stderr.flush() critical( '', output ) +def command_name(): + return basename(sys.argv[0]) + def run_main( main = None, do_force = False, runner = None, - use_sigquit_handler = False ): + use_sigquit_handler = False, handle_exceptions = False ): """ A feature-ful program starter. Configures logging and psyco, then runs the C{main} function defined in the caller's module, passing @@ -149,25 +153,32 @@ 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: - from cProfile import runctx - container = [] - try: - outpath = os.environ[ 'PYPROF' ] % \ - currentThread().getName() - except: - error( 'bad PYPROF:', os.environ[ 'PYPROF' ] ) + try: + if do_debug: + import pdb + signal(SIGINT, lambda *args: pdb.set_trace()) + status = pdb.runcall( runner, main, sys.argv ) + elif do_profile: + 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 ) + except BaseException, ex: + if handle_exceptions: + print >> sys.stderr, ex.message + sys.exit(1) else: - runctx( 'container[0] = runner( main, sys.argv )', - globals(), locals(), filename = outpath ) - status = container[0] - else: - status = runner( main, sys.argv ) + raise ## watchdog timer commits suicide if after 3 seconds we ## still have not exited This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |