Repository navigation
Conversation
Wrap open_video() in a with statement inside scenedetect.detect() so underlying file handles and decoders are deterministically closed on both normal completion and exceptions (preventing WinError 32 file locks on Windows).
MuhammadBilalKhan267
requested changes
Nov 22, 2026
MuhammadBilalKhan267
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the fix. Left one comment.
| shutil.copyfile(test_video_file, error_copy) | ||
| with pytest.raises(ValueError): | ||
| detect(error_copy, ContentDetector(), start_time="invalid_timecode") | ||
| error_copy.unlink() |
Collaborator
There was a problem hiding this comment.
Can we assert that close() is called instead of deleting the video? Linux allows deletion while the stream is still open. The test doesn't cover that.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scenedetect.detect()inscenedetect/__init__.pyopens aVideoStreamviaopen_video(video_path, backend=backend)without usingVideoStreamas a context manager. Whendetect()returns or raises an exception (such asValueErroron an invalidstart_timeorend_time), the underlying file descriptor remains open in the stack frame. On Windows, callers attempting to delete or move temporary video files immediately hitPermissionError: [WinError 32].Reproduction
Fix and Verification
open_video(video_path, backend=backend)inwith open_video(video_path, backend=backend) as video:insidescenedetect.detect().test_api_detect_closes_stream_on_return_and_errorintests/test_api.pyverifying immediatePath.unlink()cleanup after both normal execution andValueErrorexceptions (12/12test_api.pytests passing,ruff checkandruff format --checkclean).