atomicx
raw JSON → 0.0.15 verified Fri May 01 auth: no python
Easy-to-use lock-free atomic integers, booleans, and floats for Python, leveraging C11 atomics. Current version 0.0.15, requires Python >=3.8. Released under MIT license, primarily a single-developer project with infrequent releases.
pip install atomicx Common errors
error ModuleNotFoundError: No module named 'atomicx' ↓
cause Package not installed or installed in a different environment.
fix
Run 'pip install atomicx' to install the package.
error ImportError: cannot import name 'AtomicFloat' from 'atomicx' ↓
cause Version older than 0.0.15 may not have AtomicFloat; introduced in 0.0.15.
fix
Upgrade atomicx: 'pip install --upgrade atomicx'. Or import only available classes: AtomicInt and AtomicBool.
error TypeError: 'AtomicInt' object does not support item assignment ↓
cause Trying to use subscript notation like atomic[0] instead of atomic.load() or atomic.store().
fix
Use .load() to read and .store(value) to write.
Warnings
gotcha AtomicFloat does not support compound assignment operators like += because Python float operations are not atomic. Always use methods like .store() or .add() (if available) to modify the value. ↓
fix Use atomic_float.store(atomic_float.load() + 1) or check if .add() is implemented in your version.
gotcha Atomic types do not support comparison or arithmetic across threads without explicit load; comparing two atomic objects directly compares their memory addresses, not their values. ↓
fix Always use .load() to get the value before comparing: if atomic_a.load() == atomic_b.load(): ...
gotcha Initialization with non-integer for AtomicInt may raise TypeError. For AtomicFloat, only float is accepted; passing int may be coerced but not guaranteed. ↓
fix AtomicInt(0) works; AtomicFloat(0.0) works; AtomicFloat(0) may raise TypeError.
Imports
- AtomicInt
from atomicx import AtomicInt - AtomicBool
from atomicx import AtomicBool - AtomicFloat
from atomicx import AtomicFloat
Quickstart
from atomicx import AtomicInt, AtomicBool, AtomicFloat
counter = AtomicInt(0)
counter.inc()
counter.add(5)
print(counter.load())
flag = AtomicBool(False)
flag.store(True)
print(flag.load())
value = AtomicFloat(3.14)
print(value.load())