posix-ipc is a Python module, implemented in C, that provides access to POSIX inter-process communication primitives: semaphores, shared memory, and message queues. It enables Python applications to communicate with non-Python programs on systems supporting POSIX Realtime Extensions (POSIX 1003.1b-1993), including most Unix-like platforms and Windows via Cygwin or WSL. The current version is 1.3.2, with releases typically tied to bug fixes and modernization efforts rather than a strict cadence.
pip install posix-ipcVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the basic usage of POSIX semaphores, shared memory, and message queues. It shows how to create, use, and explicitly clean up these IPC objects. Note the platform-specific behavior for message queues. For shared memory, only creation and unlinking are shown; actual data exchange requires `mmap`.
Migrate away from using `posix_ipc.PAGE_SIZE` and `posix_ipc.SEMAPHORE_VALUE_MAX`. Consult system `os.sysconf` or `mmap` documentation for alternatives if needed.
Always call `obj.unlink()` on IPC objects when they are no longer needed. Use `try...finally` blocks to ensure unlinking, even if errors occur during operation. Consider using `O_EXCL` with `O_CREAT` for exclusive creation to avoid conflicts with existing objects.
Understand that `close()` is for releasing a process's reference, while `unlink()` removes the system-wide object. Call `unlink()` when the object is globally no longer needed by any process. Avoid using a `posix_ipc` object after calling `close()` on it, unless for `unlink()` or `name` access.
Be aware of platform limitations. Test IPC functionality on the target OS. For macOS, avoid message queues entirely when using `posix-ipc`. For cross-platform Python IPC, consider `multiprocessing` or `multiprocessing.shared_memory`.
If all communicating processes are Python, evaluate `multiprocessing` first for simpler and more Pythonic IPC patterns.
Ensure the semaphore object is valid and has not been closed or unlinked. If opening, use `posix_ipc.O_CREAT` to create it if it doesn't exist, or `posix_ipc.O_CREAT | posix_ipc.O_EXCL` for exclusive creation.
Check the `mode` parameter when creating IPC objects (e.g., `0o600` for owner read/write). Ensure the process has sufficient user/group permissions for the IPC object. Verify that `umask` settings are not overly restrictive.
Ensure the message queue is created with `posix_ipc.O_CREAT`. If on macOS, remember that message queues are not supported by `posix-ipc`. Verify that the queue name is consistent across processes and that permissions allow access.
No dependency data recorded yet.