{"library":"posix-ipc","title":"POSIX IPC for Python","description":"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.","language":"python","status":"active","last_verified":"Sun May 17","install":{"commands":["pip install posix-ipc"],"cli":null},"imports":["from posix_ipc import Semaphore","from posix_ipc import SharedMemory","from posix_ipc import MessageQueue","from posix_ipc import O_CREAT","from posix_ipc import O_EXCL"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import posix_ipc\nimport os\n\n# Semaphore Example\nSEM_NAME = '/my_semaphore'\ntry:\n    sem = posix_ipc.Semaphore(SEM_NAME, posix_ipc.O_CREAT, initial_value=1)\n    print(f\"Semaphore '{SEM_NAME}' created/opened. Value: {sem.value}\")\n    sem.acquire()\n    print(f\"Semaphore acquired. Value: {sem.value}\")\n    sem.release()\n    print(f\"Semaphore released. Value: {sem.value}\")\nfinally:\n    if 'sem' in locals() and sem.name == SEM_NAME: # Ensure it's our semaphore and still valid\n        sem.close()\n        sem.unlink()\n        print(f\"Semaphore '{SEM_NAME}' closed and unlinked.\")\n\n# Shared Memory Example\nSHM_NAME = '/my_shared_memory'\nSIZE = 128\ntry:\n    shm = posix_ipc.SharedMemory(SHM_NAME, posix_ipc.O_CREAT, size=SIZE)\n    print(f\"Shared Memory '{SHM_NAME}' created/opened with size {SIZE}.\")\n    # In a real app, you'd mmap this and write/read bytes\n    # e.g., memory_map = mmap.mmap(shm.fd, shm.size)\n    # memory_map.write(b'Hello from shared memory!')\nfinally:\n    if 'shm' in locals() and shm.name == SHM_NAME:\n        shm.close_fd() # Close the file descriptor\n        shm.unlink()\n        print(f\"Shared Memory '{SHM_NAME}' unlinked.\")\n\n# Message Queue Example (Note: Message queues are not supported on macOS by posix-ipc)\n# This example will likely fail on macOS due to OS limitations.\n# For a runnable example, execute on Linux/WSL.\nMQ_NAME = '/my_message_queue'\nif os.uname().sysname != 'Darwin': # Check if not macOS\n    try:\n        mq = posix_ipc.MessageQueue(MQ_NAME, posix_ipc.O_CREAT, max_messages=10, max_message_size=64)\n        print(f\"Message Queue '{MQ_NAME}' created/opened.\")\n        message = b\"Hello from message queue!\"\n        mq.send(message)\n        print(f\"Sent: {message.decode()}\")\n        received_message, _ = mq.receive()\n        print(f\"Received: {received_message.decode()}\")\n    except posix_ipc.PermissionsError as e:\n        print(f\"Caught PermissionsError for MessageQueue: {e}. This might happen if queue exists with different permissions.\")\n    except posix_ipc.ExistentialError as e:\n        print(f\"Caught ExistentialError for MessageQueue: {e}. This might happen if queue exists with incompatible settings.\")\n    except Exception as e:\n        print(f\"An unexpected error occurred with MessageQueue: {e}\")\n    finally:\n        if 'mq' in locals() and mq.name == MQ_NAME:\n            try:\n                mq.close()\n                mq.unlink()\n                print(f\"Message Queue '{MQ_NAME}' closed and unlinked.\")\n            except Exception as e:\n                print(f\"Error during MessageQueue cleanup: {e}\")\nelse:\n    print(\"MessageQueue example skipped: Not supported on macOS by posix-ipc.\")\n","lang":"python","description":"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`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-17","installed_version":"1.3.2","pypi_latest":"1.3.2","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":1.5,"avg_import_s":0,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"posix-ipc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"17.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"posix-ipc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0,"mem_mb":0,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"posix-ipc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"19.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"posix-ipc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.6,"import_time_s":0,"mem_mb":0,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"posix-ipc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"11.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"posix-ipc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.4,"import_time_s":0,"mem_mb":0,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"posix-ipc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"11.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"posix-ipc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.4,"import_time_s":0,"mem_mb":0,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"posix-ipc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"17.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"posix-ipc","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.8,"import_time_s":0,"mem_mb":0,"disk_size":"18M"}]}}