Skip to content

Semaphore Leak Warning on Python 3.13.7 with Kokoro TTS in Async Context #244

@Mohammed-Yasin-Mulla

Description

@Mohammed-Yasin-Mulla

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

  1. Set LOKY_MAX_CPU_COUNT=1 → Reduced warnings but still appear occasionally
  2. 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)
  3. Aggressive GC → Minimal impact
  4. Force CPU mode (disabled MPS) → Improved stability, warnings persist

Questions

  1. Does mlx-audio use joblib internally? (I see it's in dependencies)
  2. Is there a recommended async pattern for long-running services?
  3. Are there known Python 3.13.7 compatibility issues?
  4. Does model.generate() spawn background processes?
  5. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions