Skip to content

gh-134634: Use a pipe instead of a queue for Pool's change notifier#148050

Closed
yonatan-genai wants to merge 3 commits intopython:mainfrom
yonatan-genai:gh-134634-pool-pipe-notifier
Closed

gh-134634: Use a pipe instead of a queue for Pool's change notifier#148050
yonatan-genai wants to merge 3 commits intopython:mainfrom
yonatan-genai:gh-134634-pool-pipe-notifier

Conversation

@yonatan-genai
Copy link
Copy Markdown

@yonatan-genai yonatan-genai commented Apr 3, 2026

Summary

Pool.__init__ used a multiprocessing.SimpleQueue for its internal _change_notifier, a mechanism that wakes up the worker handler thread when the pool state changes (close, terminate, cache empty). SimpleQueue creates two Lock objects backed by POSIX named semaphores via sem_open(), which requires /dev/shm to be mounted as tmpfs.

The change notifier never crosses a process boundary. It is only accessed by threads within the parent process (the worker handler, result handler, and main thread). Named semaphores were never needed here.

This replaces the SimpleQueue with a _ChangeNotifier class backed by multiprocessing.connection.Pipe (which wraps os.pipe()). It provides the same interface (put, get, empty, _reader) without requiring sem_open().

Impact

Both multiprocessing.Pool and multiprocessing.pool.ThreadPool fail on platforms without /dev/shm, even though ThreadPool only uses threads and never needs inter-process synchronization. Affected platforms include AWS Lambda (no /dev/shm), Android and iOS (sem_open() unavailable), and Docker containers with restricted shared memory.

Changes

  • Lib/multiprocessing/pool.py: Add _ChangeNotifier class, replace the one line in Pool.__init__ that created the SimpleQueue
  • Lib/test/_test_multiprocessing.py: Three new tests — notifier type verification + end-to-end pool.map, notification drain under load, worker process recovery after SIGKILL
  • Misc/NEWS.d/next/Library/: NEWS entry

Testing

Full test_multiprocessing_spawn suite: 447 tests passed, 0 failures. Reference leak check passed.

…fier

Pool.__init__ used a multiprocessing.SimpleQueue for its internal
_change_notifier. SimpleQueue creates Lock objects backed by POSIX
named semaphores (sem_open), which requires /dev/shm. The change
notifier never crosses a process boundary, so named semaphores were
never needed.

Replace it with a _ChangeNotifier class backed by
multiprocessing.connection.Pipe (os.pipe). Same interface, no
sem_open dependency.

<claude>
@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Apr 3, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

yonatan-genai and others added 2 commits April 3, 2026 21:25
The new tests need @warnings_helper.ignore_fork_in_thread_deprecation_warnings()
to avoid DeprecationWarning when creating Pool with the fork start method
in a multi-threaded test process (Python 3.14+ strictness).

<claude>
@yonatan-genai
Copy link
Copy Markdown
Author

The macOS / build and test (macos-26) failure is unrelated to this change — it's test_perf_profiler.TestPerfTrampoline.test_trampoline_works_with_forks failing with a non-zero child exit code. This test has a known flakiness issue related to fork child finalization (see gh-144766). I'll submit a separate fix for it.

@gpshead
Copy link
Copy Markdown
Member

gpshead commented Apr 3, 2026

https://devguide.python.org/getting-started/generative-ai/

I see no evidence of a person being involved here and thus doubt the CLA was signed by a human with legal authority to do so.

@gpshead gpshead closed this Apr 3, 2026
@yonatan-genai
Copy link
Copy Markdown
Author

yonatan-genai commented Apr 4, 2026 via email

@yonatan-genai
Copy link
Copy Markdown
Author

I’d appreciate it if you could consider reopening…

@serhiy-storchaka serhiy-storchaka self-requested a review April 4, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants