fix(race condition): fixing race condition in stop_recording (wait for proper stop before cleaning)

This commit is contained in:
CarolinePascal
2025-12-25 23:26:43 +01:00
parent 5cd3572713
commit 538cea6dbc
2 changed files with 7 additions and 6 deletions

View File

@@ -1435,7 +1435,7 @@ class LeRobotDataset(torch.utils.data.Dataset):
for video_key in self.meta.video_keys:
ep_metadata.update(self._save_episode_video(video_key, episode_index))
#TODO(Caroline): add parallel encoding for audio as well
# TODO(Caroline): add parallel encoding for audio as well
for audio_key in self.meta.audio_keys:
ep_metadata.update(self._save_episode_audio(audio_key, episode_index))

View File

@@ -497,6 +497,12 @@ class PortAudioMicrophone(Microphone):
self.record_start_event.clear() # Ensures the audio stream is not started again !
self.record_stop_event.set()
# Wait for the stream to be stopped (might lead to race condition if the stream is not properly stopped on array reset and queue clearing)
timeout = 1.0
while self.is_recording and timeout > 0:
time.sleep(0.01)
timeout -= 0.01
self.read_shared_array.reset()
self._clear_queue(self.write_queue, join_queue=True)
@@ -504,11 +510,6 @@ class PortAudioMicrophone(Microphone):
self.write_stop_event.set()
self.write_thread.join()
timeout = 1.0
while self.is_recording and timeout > 0:
time.sleep(0.01)
timeout -= 0.01
if self.is_recording:
raise RuntimeError(f"Error stopping recording for microphone {self.microphone_index}.")
if self.is_writing: