Repository navigation
[bugfix] Close video stream in detect() via context manager - #616
Merged
Breakthrough merged 3 commits intoNov 29, 2026
Merged
Conversation
MuhammadBilalKhan267
previously requested changes
Nov 22, 2026
MuhammadBilalKhan267
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the fix. Left one comment.
Breakthrough
force-pushed
the
main
branch
2 times, most recently
from
November 24, 2026 03:31
9f4c933 to
a696070
Compare
Contributor
Author
|
Updated |
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).
M-Colley
force-pushed
the
fix/detect-close-video-stream
branch
from
November 27, 2026 21:46
1fb7f73 to
46619b1
Compare
| import shutil | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import scenedetect |
Owner
There was a problem hiding this comment.
Can you use monkeypatch.setattr("scenedetect.open_video", tracking_open_video) and add open_video to the from scenedetect import ... line, so the import scenedetect can be removed (fixing this warning)?
Breakthrough
approved these changes
Nov 29, 2026
Breakthrough
left a comment
Owner
There was a problem hiding this comment.
I want to cut 0.7.4, will address any unresolved issues on main. Thanks for the PR!
Breakthrough
approved these changes
Nov 29, 2026
Breakthrough
dismissed
MuhammadBilalKhan267’s stale review
November 29, 2026 23:14
Addressed in 46619b1: the test now asserts close() is called on return and on error.
Breakthrough
added a commit
that referenced
this pull request
Nov 29, 2026
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).