Skip to content

Release the export pool when a Separator is collected - #960

Open
Yius wants to merge 2 commits into
deezer:masterfrom
Yius:fix/separator-pool-lifetime
Open

Yius wants to merge 2 commits into
deezer:masterfrom
Yius:fix/separator-pool-lifetime

Conversation

@Yius

@Yius Yius commented Nov 10, 2026

Copy link
Copy Markdown
  • Read the contributing guidelines.
  • Checked for an open PR with the same fix.
  • The change is limited to Spleeter.

Description

Creating and discarding a Separator leaves its audio export workers alive until the Python process exits. The bound Pool.close method registered with atexit keeps the pool alive after the separator is collected. On a two-CPU Linux container, creating and releasing three instances left six workers running and increased the open file descriptor count from 4 to 34.

Tie cleanup to the lifetime of the separator with a weak reference finalizer. The finalizer closes the pool in its owning process. Pool.close() lets submitted exports finish before the workers exit. Starting the pool in the constructor avoids moving the fork after TensorFlow inference.

How this patch was tested

  • On Linux arm64 with Python 3.11.18, TensorFlow 2.12.1 and FFmpeg 5.1.9, the same three-instance probe returned to zero workers and four open file descriptors after the change.
  • On the base commit, two added tests failed because workers remained alive and the synchronous WAV export test passed. All three pass with the change. The asynchronous test releases the separator while one write is running and a second is queued, then verifies both outputs and worker exit.
  • A separate run of separate_to_file(..., synchronous=False) with the pretrained two-stem model and real FFmpeg verified two complete stereo WAVs at 44.1 kHz after the separator was collected. The pool went from two workers to zero.
  • The full upstream pytest suite passed (35 tests). Black, Flake8 and isort checks passed.

References

Related to #725. An LLM assisted with repository analysis, patch preparation, testing, and drafting this PR.

Yius added 2 commits November 10, 2026 17:40
…n a Separator is collected

Replaced atexit registration with weakref.finalize for pool closure.
Add tests for audio export process pool management.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant