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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ipctools-0.1.1.tar.gz.
File metadata
- Download URL: ipctools-0.1.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f59ff3e278b702713c559c85163e44931b2bbe9346db444fae3f274078e8cbc5
|
|
| MD5 |
a9c155830421c11831729ecc62648b4b
|
|
| BLAKE2b-256 |
4bff04ff36a3d45f842291c6c9db350b9dba48a4a562d5ce6360eef9d0e06a50
|
File details
Details for the file ipctools-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ipctools-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe6c53ea742cd21ca0c5a21543927db795af614c2b2bcca26740f568bd6f94e9
|
|
| MD5 |
3e29c27bdeb0a3dae75074d966e9197d
|
|
| BLAKE2b-256 |
35b959e916e61b88415a7b613ecbb2e8257180a36880a7455d8bd0533b8c813f
|