Fix graceful process shutdown in macOS app#1372
Merged
AlexCheema merged 7 commits intomainfrom Feb 17, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
Author
|
Hey @Evanev7 can you check this? Does it make sense to also catch SIGTERM like this? |
Evanev7
approved these changes
Feb 4, 2026
Member
Evanev7
left a comment
There was a problem hiding this comment.
yeah catching sigterm is fine
…ul-process-shutdown
…ul-process-shutdown
Resolve merge conflict in main.py by keeping signal handlers at the top of the run method (before task startup). Exclude tests/start_distributed_test.py from pytest collection as it's a standalone script, not a test module. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ul-process-shutdown
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.
Motivation
Fixes #1370
When the macOS app stops exo, GPU/system memory isn't released. This happens because:
process.terminate()(SIGTERM) but the Python process only registers a graceful shutdown handler for SIGINT, not SIGTERM. SIGTERM's default Python behavior raisesSystemExitwhich bypasses the cleanup cascade (runner subprocess MLX cleanup viamx.clear_cache(), channel closing, etc.).Changes
src/exo/main.py: Register SIGTERM handler alongside SIGINT so the graceful shutdown cascade (Node.shutdown()→ cancel task group → worker/runner cleanup →mx.clear_cache()+gc.collect()) runs regardless of which signal is received.app/EXO/EXO/ExoProcessController.swift: Replace immediateprocess.terminate()with escalating shutdown per @Evanev7's suggestion:process.interrupt()— triggers the registered Python handler for graceful cleanupprocess.terminate()The escalation runs in a detached
Taskso the UI updates immediately (status → stopped) without blocking.Why It Works
The root cause is that SIGTERM wasn't triggering the graceful shutdown path. By registering a SIGTERM handler in Python and sending SIGINT first from the macOS app, the process gets a chance to run the full cleanup cascade: cancelling the task group, shutting down runners (which call
del model; mx.clear_cache(); gc.collect()), closing channels, and flushing logs. The escalation to SIGTERM and SIGKILL ensures the process always terminates even if graceful shutdown hangs.Test Plan
Manual Testing
Automated Testing
uv run basedpyright— 0 errorsuv run ruff check— passesnix fmt— no changes