def execute_fairplay(player, **kwargs): if player == 'bob': cmd = cmd_for_bob(**kwargs) else: cmd = cmd_for_alice(**kwargs) root = kwargs.get('root') fortune = kwargs.pop('fortune') logger = setupLogger(remote_logs_dir_F(root), DEBUG, DEBUG) logger.info('begin ~') path = rjoin(root, inject_folder_name, 'run') results_wrapper()(ubt.benchmark_wrapper()(lambda : do(cmd, fortune, path)))() logger.info('end ~')
wrapping the function in a results wrapper and a benchmark wrapper. Notice how the optional timeout parameter is managed. ------------------------------------------------------------------------------- """ import sys from shared_lib.collection import ubt from shared_lib.collection import \ setupLogger, DEBUG, remote_logs_dir_F, root, \ results_wrapper, parse_params # _Setup logger_ logger = setupLogger(remote_logs_dir_F(root), DEBUG, DEBUG) # _Fib, the function to be tested_ def fib(x): if x < 3: return x else: return fib(x-1) + fib(x-2) # # Results wrapper and benchmark wrapper # transparently handles benchmarking, # the given script and saves it to a results file # if __name__ == '__main__': params = parse_params(sys.argv)