diff options
Diffstat (limited to 'sim.py')
-rwxr-xr-x | sim.py | 26 |
1 files changed, 3 insertions, 23 deletions
@@ -11,34 +11,14 @@ import generator from generator import constant import gpu from fileio import root -import ROOT +from tools import profile_if_possible, enable_debug_on_crash def pick_seed(): '''Returns a seed for a random number generator selected using a mixture of the current time and the current process ID.''' return int(time.time()) ^ (os.getpid() << 16) -def info(type, value, tb): - if hasattr(sys, 'ps1') or not sys.stderr.isatty(): - # we are in interactive mode or we don't have a tty-like - # device, so we call the default hook - sys.__excepthook__(type, value, tb) - else: - import traceback, pdb - # we are NOT in interactive mode, print the exception... - traceback.print_exception(type, value, tb) - print - # ...then start the debugger in post-mortem mode. - pdb.pm() - - -# Allow profile decorator to exist, but do nothing if not running under kernprof -try: - profile = profile -except NameError: - profile = lambda x: x - -@profile +@profile_if_possible def main(): parser = optparse.OptionParser('%prog') parser.add_option('-b', type='int', dest='nbits', default=10) @@ -148,5 +128,5 @@ def main(): print >>sys.stderr, 'Done. %1.1f events/sec, %1.0f photons/sec.' % (options.nevents/(end_sim - start_sim), nphotons/(end_sim - start_sim)) if __name__ == '__main__': - sys.excepthook = info + enable_debug_on_crash() main() |