Various
[python_utils.git] / bootstrap.py
index 3c886efc94f583e7b13a7bbc19d63a174890d120..3b03b3a691b5bb823a3f0548a616358eff93ee96 100644 (file)
@@ -12,7 +12,7 @@ import traceback
 
 from argparse_utils import ActionNoYes
 import config
-
+import logging_utils
 
 logger = logging.getLogger(__name__)
 
@@ -48,9 +48,14 @@ def initialize(entry_point):
     @functools.wraps(entry_point)
     def initialize_wrapper(*args, **kwargs):
         sys.excepthook = handle_uncaught_exception
-        config.parse(entry_point.__globals__['__file__'])
+        if (
+                '__globals__' in entry_point.__dict__ and
+                '__file__' in entry_point.__globals__
+        ):
+            config.parse(entry_point.__globals__['__file__'])
+        else:
+            config.parse(None)
 
-        import logging_utils
         logging_utils.initialize_logging(logging.getLogger())
 
         config.late_logging()
@@ -58,8 +63,8 @@ def initialize(entry_point):
         logger.debug(f'Starting {entry_point.__name__} (program entry point)')
 
         ret = None
-        import timer
-        with timer.Timer() as t:
+        import stopwatch
+        with stopwatch.Timer() as t:
             ret = entry_point(*args, **kwargs)
         logger.debug(
             f'{entry_point.__name__} (program entry point) returned {ret}.'
@@ -67,13 +72,13 @@ def initialize(entry_point):
 
         walltime = t()
         (utime, stime, cutime, cstime, elapsed_time) = os.times()
-        logger.debug(f'\n'
+        logger.debug('\n'
                      f'user: {utime}s\n'
                      f'system: {stime}s\n'
                      f'child user: {cutime}s\n'
                      f'child system: {cstime}s\n'
-                     f'elapsed: {elapsed_time}s\n'
-                     f'walltime: {walltime}s\n')
+                     f'machine uptime: {elapsed_time}s\n'
+                     f'walltime: {walltime}s')
         if ret != 0:
             logger.info(f'Exit {ret}')
         else: