fix(macos): app hangs on quit and must be force-killed#162
Open
henricook wants to merge 1 commit into
Open
Conversation
pystray's NSApplication run loop, the tkinter interpreter that is never destroyed, and the native daemon threads (websocket-client, pasteboard, aiortc) stall interpreter finalization after the tray icon stops, so the process hangs on quit and has to be force-killed. Force immediate termination with os._exit(0) once the websocket is disconnected and the single-instance lock has been released.
2d046ac to
57146dd
Compare
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.
On macOS the app never quits cleanly - the menu-bar Quit stops the tray icon, but the process stays hung and has to be force-killed (and it blocks OS shutdown/logout with the "app failed to quit" nag).
icon.stop()the main thread comes out of pystray'sNSApplicationloop and tries to finalize the interpreter, but the tkinter root is never destroyed and several native daemon threads (websocket-client blocked in an SSLrecv, pasteboard/pyobjus, and the aiortc asyncio loop in P2P mode) stall finalization. Daemon flags don't help here - the stall is in the finalization itself, so the process just hangs.os._exit(0)on macOS so it terminates immediately instead of waiting on the stuck clean-exit path. Both Quit and Logoff-and-Quit funnel back throughrun()'sfinally, so this one spot covers both.