adding extra guard like dagged with try except finally

This commit is contained in:
Maximellerbach
2026-06-03 17:13:32 +02:00
parent 7a843d8f93
commit 7579ad320e
+9
View File
@@ -31,6 +31,7 @@ Dataset naming follows the rollout convention: repo names must start with ``roll
from __future__ import annotations
import contextlib
import logging
import time
@@ -104,6 +105,7 @@ class LegacyStrategy(RolloutStrategy):
)
with VideoEncodingManager(dataset):
try:
recorded_episodes = 0
while recorded_episodes < num_episodes and not events["stop_recording"]:
if ctx.runtime.shutdown_event.is_set():
@@ -151,6 +153,13 @@ class LegacyStrategy(RolloutStrategy):
dataset.save_episode()
recorded_episodes += 1
finally:
# Save any frames buffered in the current episode so an unexpected
# exception or KeyboardInterrupt does not silently drop recorded data.
# suppress: save_episode raises if the buffer is empty (nothing to lose).
logger.info("Legacy control loop ended — saving any in-progress episode")
with contextlib.suppress(Exception):
dataset.save_episode()
def _policy_loop(
self,