X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=bootstrap.py;h=9bffaf535bf48e310a2006a489ac43242c20f99a;hb=2bf59f4f017a7497aaf0449bdf77e130abdf36d8;hp=50af84407f57e504632e868a1b1e2de32a19a671;hpb=beac1437b595ed543595b12b81ab637d4737038a;p=python_utils.git diff --git a/bootstrap.py b/bootstrap.py index 50af844..9bffaf5 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -241,10 +241,16 @@ def initialize(entry_point): # Try to figure out the name of the program entry point. Then # parse configuration (based on cmdline flags, environment vars # etc...) - if '__globals__' in entry_point.__dict__ and '__file__' in entry_point.__globals__: - config.parse(entry_point.__globals__['__file__']) - else: - config.parse(None) + entry_filename = None + entry_descr = None + try: + entry_filename = entry_point.__code__.co_filename + entry_descr = entry_point.__code__.__repr__() + except Exception: + if '__globals__' in entry_point.__dict__ and '__file__' in entry_point.__globals__: + entry_filename = entry_point.__globals__['__file__'] + entry_descr = entry_filename + config.parse(entry_filename) if config.config['trace_memory']: import tracemalloc @@ -287,7 +293,7 @@ def initialize(entry_point): random.seed(random_seed) # Do it, invoke the user's code. Pay attention to how long it takes. - logger.debug('Starting %s (program entry point)', entry_point.__name__) + logger.debug('Starting %s (program entry point)', entry_descr) ret = None import stopwatch @@ -307,7 +313,7 @@ def initialize(entry_point): with stopwatch.Timer() as t: ret = entry_point(*args, **kwargs) - logger.debug('%s (program entry point) returned %s.', entry_point.__name__, ret) + logger.debug('%s (program entry point) returned %s.', entry_descr) if config.config['trace_memory']: snapshot = tracemalloc.take_snapshot()