Skip to main content

Inter-process communication tools.

Project description

Ipctools is a library to facilitate inter-process communication.

Installation

pip install ipctools

Usage

The store API is used to get or set values in a key-value store. This store is implemented as a temporary file on the system. The default file location may be overridden with the IPCTOOLS_STORE environment variable.

Set, and get a value from the store.

from ipctools import store

store.set_value("my_key", "my_value")
value = store.get_value("my_key")
assert value == "my_value"

Setting a value updates it if exists.

store.set_value("my_key", "my_value_1")
store.set_value("my_key", "my_value_2")
value = store.get_value("my_key")
assert value == "my_value_2"

However, creating a value will fail if it already exits. You can perform leader election across multiple processes by having each one try to set a value. Only one process will succeed, so that one can be the leader.

import os

from ipctools import store

is_leader = store.create_value("leader", str(os.getpid()))

Since the value of leader was set to the process ID of a single process, any process can also determine who the leader is.

def am_i_the_leader() -> bool:
    return store.get_value("leader") == str(os.getpid())

If mutliple processes try to set a value at the same time, some of them may fail. You can try to set a value with retries.

store.try_set_value("my_key", "my_value", retries=2)

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

ipctools-0.2.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

ipctools-0.2.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file ipctools-0.2.1.tar.gz.

File metadata

  • Download URL: ipctools-0.2.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ipctools-0.2.1.tar.gz
Algorithm Hash digest
SHA256 cd2aac92c0d8d796328fc5cf4068383ed2aff16842ca5e6a2061f1b8b615815b
MD5 d15b6b7ff49a5e9dd76e5eee525ac076
BLAKE2b-256 dfbe501de85f076885dfbca10169e60168c77a9f22790976d9a034e0a61ce38d

See more details on using hashes here.

File details

Details for the file ipctools-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ipctools-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ipctools-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ed804a71fb554990260bcf8fd8dce68df7189456feafd9fdd76b64e628623cf5
MD5 6c634904c93892a583859b3732f584bb
BLAKE2b-256 1fdfeba83baf178ad6b96c3db252c3e7d42081832c22f03214276c6297d0b36f

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