Skip to content

Commit 877eb0c

Browse files
authored
Fix windows dll context manager (#1120)
1 parent 2c2a138 commit 877eb0c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/torchcodec/_core/ops.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,19 @@ def load_torchcodec_shared_libraries() -> tuple[int, str]:
8888
)
8989

9090

91+
expose_ffmpeg_dlls = nullcontext
9192
if sys.platform == "win32" and hasattr(os, "add_dll_directory"):
9293
# On windows we try to locate the FFmpeg DLLs and temporarily add them to
9394
# the DLL search path. This seems to be needed on some users machine, but
9495
# not on our CI. We don't know why.
9596
if ffmpeg_path := shutil.which("ffmpeg"):
9697

97-
def cm(): # noqa: F811
98+
def expose_ffmpeg_dlls(): # noqa: F811
9899
ffmpeg_dir = Path(ffmpeg_path).parent
99100
return os.add_dll_directory(str(ffmpeg_dir)) # that's the actual CM
100101

101-
else:
102-
cm = nullcontext
103102

104-
with cm():
103+
with expose_ffmpeg_dlls():
105104
ffmpeg_major_version, core_library_path = load_torchcodec_shared_libraries()
106105

107106

0 commit comments

Comments
 (0)