From e83b9beb9bb0696c22c47ee6bf42c271899a92c6 Mon Sep 17 00:00:00 2001 From: gustavogaldinoo <166517299+gustavogaldinoo@users.noreply.github.com> Date: Fri, 19 Apr 2024 12:12:40 -0300 Subject: [PATCH] Improving log message (#1971) Improving log message by displaying only function name, instead of trying to print function itself. Also took the opportunity to replace `Callable` with `FunctionType` when declaring argument type, as Callable is more generic. --- experiment/build/builder.py | 8 +++++--- experiment/build/test_builder.py | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/experiment/build/builder.py b/experiment/build/builder.py index bdfbd6c71..d66ae30d3 100644 --- a/experiment/build/builder.py +++ b/experiment/build/builder.py @@ -22,7 +22,8 @@ import subprocess import sys import time -from typing import Callable, List, Tuple +import types +from typing import List, Tuple from common import benchmark_config from common import benchmark_utils @@ -135,7 +136,8 @@ def split_successes_and_failures(inputs: List, return successes, failures -def retry_build_loop(build_func: Callable, inputs: List[Tuple]) -> List: +def retry_build_loop(build_func: types.FunctionType, + inputs: List[Tuple]) -> List: """Calls |build_func| in parallel on |inputs|. Repeat on failures up to |NUM_BUILD_ATTEMPTS| times. Returns the list of inputs that |build_func| was called successfully on.""" @@ -144,7 +146,7 @@ def retry_build_loop(build_func: Callable, inputs: List[Tuple]) -> List: logs.info('Concurrent builds: %d.', num_concurrent_builds) with mp_pool.ThreadPool(num_concurrent_builds) as pool: for _ in range(NUM_BUILD_ATTEMPTS): - logs.info('Building using (%s): %s', build_func, inputs) + logs.info('Building using (%s): %s', build_func.__name__, inputs) results = pool.starmap(build_func, inputs) curr_successes, curr_failures = split_successes_and_failures( inputs, results) diff --git a/experiment/build/test_builder.py b/experiment/build/test_builder.py index 5f9e79153..ee4c8bb2c 100644 --- a/experiment/build/test_builder.py +++ b/experiment/build/test_builder.py @@ -78,6 +78,9 @@ def test_build_all_measurers(mocked_build_utils, mocked_fs, mocked_time, """Tests that build_all_measurers works as intendend when build_measurer calls fail.""" mocked_build_measurer.return_value = build_measurer_return_value + # Required cause logs uses the name of the build + # measurer function, so it cant be unset + mocked_build_measurer.__name__ = 'Mocked function' benchmarks = get_regular_benchmarks() result = builder.build_all_measurers(benchmarks) if build_measurer_return_value: