Semaphore Leak Warning on Python 3.13.7 with Kokoro TTS in Async Context
Environment
- mlx-audio: v0.2.5
-
Model:
mlx-community/Kokoro-82M-bf16 - Python: 3.13.7
- Machine: MacBook Pro M3 Pro (18GB RAM)
- OS: macOS 26.0.1
Issue
Getting persistent semaphore leak warnings from Python's resource_tracker when using mlx-audio for real-time TTS:
INFO:whisperlivekit.audio_processor:internal_buffer=0.00s | lag=0.29s |
/Users/mohammedyasinmulla/.local/share/uv/python/cpython-3.13.7-macos-aarch64-none/lib/python3.13/multiprocessing/resource_tracker.py:324: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown: {'/loky-12097-8myixz42'}
When it occurs:
- At first audio generation (client connection)
Attempted Fixes
- ✅ Set
LOKY_MAX_CPU_COUNT=1→ Reduced warnings but still appear occasionally - ✅ Explicit loky cleanup:
from joblib.externals.loky import get_reusable_executor executor = get_reusable_executor(max_workers=None, timeout=1) executor.shutdown(wait=True, kill_workers=True) - ✅ Aggressive GC → Minimal impact
- ✅ Force CPU mode (disabled MPS) → Improved stability, warnings persist
Questions
- Does mlx-audio use
joblibinternally? (I see it's in dependencies) - Is there a recommended async pattern for long-running services?
- Are there known Python 3.13.7 compatibility issues?
- Does
model.generate()spawn background processes? - Proper cleanup procedure for MLX models in async context?
Related:
- Also using
mlx-whisper(via WhisperLiveKit) in same process - Both may involve joblib/loky → cumulative effect?
Hey @Mohammed-Yasin-Mulla
Could you provide a reproducible example?
Also, we have whisper support in mlx-audio.
Finally, leaked semaphore means that a process is consuming all your memory, maybe it's mlx-whisper + whisperLivekit combo.
Hey @Blaizzy
Please check my repo: https://github.com/Mohammed-Yasin-Mulla/Local-Voice-AI/tree/mlx-audio
In the mlx-audio branch
This sometimes randomly works out of the blue, and most of the time gives me this error above.
Hey @Mohammed-Yasin-Mulla
This code base is vast, it would help and be much faster if you could pinpoint the issue for me to investigate.
I don’t know where to start as I’m not familiar with it.