Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lf.eval.v2: Handle potential race condition when saving 'index.html'. #390

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions langfun/core/eval/v2/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def _on_bound(self):
self._update_thread = None
self._stop_update = False
self._stop_update_experiment_ids = set()
self._experiment_index_lock = None

def on_run_start(
self,
Expand All @@ -61,6 +62,9 @@ def on_run_start(
self._last_experiment_report_time = {leaf.id: 0 for leaf in root.leaf_nodes}
self._stop_update = False
self._stop_update_experiment_ids = set()
self._experiment_index_lock = {
leaf.id: threading.Lock() for leaf in root.leaf_nodes
}
self._update_thread = threading.Thread(
target=self._update_thread_func, args=(runner,)
)
Expand Down Expand Up @@ -170,7 +174,8 @@ def _save():
card_view=False,
),
)
html.save(index_html_path)
with self._experiment_index_lock[experiment.id]:
html.save(index_html_path)
experiment.info(
f'Updated {index_html_path!r} in {t.elapse:.2f} seconds.',
)
Expand All @@ -185,11 +190,11 @@ def _save():
time.time() - self._last_experiment_report_time[experiment.id]
> self.experiment_report_interval
):
self._last_experiment_report_time[experiment.id] = time.time()
if background:
runner.background_run(_save)
else:
_save()
self._last_experiment_report_time[experiment.id] = time.time()

def _save_example_html(
self, runner: Runner, experiment: Experiment, example: Example
Expand Down
Loading