mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-11 14:49:43 +00:00
fix(datasets): close file handle on VideoDecoder init failure in cache (#3542)
If VideoDecoder() raises during initialization, the fsspec file handle was leaked since it was opened via __enter__() but never closed on the exception path. Now explicitly closes the handle before re-raising.
This commit is contained in:
@@ -282,7 +282,11 @@ class VideoDecoderCache:
|
|||||||
with self._lock:
|
with self._lock:
|
||||||
if video_path not in self._cache:
|
if video_path not in self._cache:
|
||||||
file_handle = fsspec.open(video_path).__enter__()
|
file_handle = fsspec.open(video_path).__enter__()
|
||||||
decoder = VideoDecoder(file_handle, seek_mode="approximate")
|
try:
|
||||||
|
decoder = VideoDecoder(file_handle, seek_mode="approximate")
|
||||||
|
except Exception:
|
||||||
|
file_handle.close()
|
||||||
|
raise
|
||||||
self._cache[video_path] = (decoder, file_handle)
|
self._cache[video_path] = (decoder, file_handle)
|
||||||
|
|
||||||
return self._cache[video_path][0]
|
return self._cache[video_path][0]
|
||||||
|
|||||||
Reference in New Issue
Block a user