Skip to main content

Inter-process spinlock using shared memory and compare-and-swap implemented in C for Python.

Project description

A Simple Atomic CAS-Based Spin Lock for Python IPC

Python's multiprocessing.shared_memory module, introduced in Python 3.8, provides a way to implement named shared memory for inter-process communication. It is somewhat analogous to the POSIX shared memory API.

However, Python's standard library does not directly support named semaphores based on the POSIX sem_open concept for inter-process synchronization by name. This is a very serious inconvenience when you work with shared memory and need to synchronize data access to this memory from multiple processes.

As one solution pypi.org has the following library: https://pypi.org/project/named_semaphores/

This repo is a very simplified version of just a spin lock, based on the compare and swap operation. It is using a 1 byte flag in shared memory at a given memory offset offest.

The need for something like this appeared when I was writing trading strategies that were somewhat pushing Python's performance boundaries. I needed to share the whole strategy's order cache (locally stored list of orders that are still open in the market) across processes of my market making strategy, each one serving it's own order book depth. I couldn't trust the standard Python IPC API because it is not designed for low-latency applications.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shm_ipc_lock-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shm_ipc_lock-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file shm_ipc_lock-0.1.0.tar.gz.

File metadata

  • Download URL: shm_ipc_lock-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0rc3

File hashes

Hashes for shm_ipc_lock-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4fc292a9365b8cfb26cd2d5801faed557b203f3b3d14e3dec060abdc3aea4c4e
MD5 88b04dfed2f7dc6e7ad5137724ae13ec
BLAKE2b-256 1c376b73a0d6e7439bf2028c30a288e567447c2a27b727f458067e115401fb14

See more details on using hashes here.

File details

Details for the file shm_ipc_lock-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: shm_ipc_lock-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0rc3

File hashes

Hashes for shm_ipc_lock-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 226a9d3f9f000302812214d4efa0ce7fa135cfac52e47c7fb5f25751d3be693d
MD5 7c9709036f6801debf85c2b88b94c5f6
BLAKE2b-256 4492cd214116d68f014e79f9684e3b33fc401715d87b8d76a22b1cc1a2d299f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page