Skip to content

Commit

Permalink
Improving log message (#1971)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gustavogaldinoo authored Apr 19, 2024
1 parent 05beb54 commit e83b9be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions experiment/build/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions experiment/build/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit e83b9be

Please sign in to comment.