Repository navigation
Fix macOS main-thread runloop deadlock in wait_for_playback/wait_for_property (Fixes #61) - #317
Closed
klintworthbowthorpe wants to merge 1 commit into
Closed
klintworthbowthorpe wants to merge 1 commit into
klintworthbowthorpe wants to merge 1 commit into
Conversation
Author
|
Closing this PR—this approach was not verified on a physical macOS Cocoa/AppKit display environment. Apologies for the noise. |
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 of Changes
Fixes #61 ("Stuck in threading on macOS").
Problem
On macOS, libmpv event dispatching and window rendering require an active Cocoa/CoreFoundation runloop on the main thread. When calling
wait_for_playback()orwait_for_property()from the main thread, python-mpv previously blocked unconditionally onFuture.result(), which invokesthreading.Condition.wait(). This puts the Python main thread to sleep in pthread condition wait without pumping the macOS run loop, causing Cocoa UI events to freeze, the dock icon to bounce indefinitely, and playback/property events to deadlock.Solution
_pump_macos_main_loop()using nativectypesbindings to/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation(CFRunLoopRunInMode), requiring zero third-party dependencies (no PyObjC required)._wait_for_future(future, timeout=None)inMPV. When running on the macOS main thread, it slices the wait into 20ms intervals and pumps the default run loop while releasing the Python GIL to allow background event handling threads to execute concurrently.tests/test_macos_threading.pycovering timeout, exceptions, main/secondary thread behavior, and actual playback.