Skip to main content

Atomicity is a simple library to provide atomic operation to python's synchronization primitives for multi-threading

Project description

atomicity

PyPI version

Atomicity is a simple library that provides atomic operation to python's synchronization primitives used in multi-threading application.

*** Note: This is at a very early stage and is subject to changes. Use at your own risk. ***

It includes an atomic lock and counter class, ensuring (somewhat) thread-safety and prevention of race conditions in concurrent programming. Everything is entirely lock-free and is backed by Rust's atomic types.

Features

TBD

Installation

Binary wheels are provided for Python 3.8 and above on Linux, macOS, and Windows:

pip install atomicity

On Windows systems, The LLVM Compiler Infrastructure is required

Usage

See the documentation for more information. Here's a quick overview:

Atomic Counter

from atomicity import AtomicCounter

# Create an atomic integer with an initial value of 0
atom = AtomicCounter()

# Perform atomic operations
atom.set(10)
value = atom.get()
print(f"Value: {value}")

previous_value = atom.add( 20)
print(f"Previous Value: {previous_value}")

atom.sub(5)
print(f"Result after addition: {atom}")

# Increment and decrement operations
atom.increment()
atom.decrement()

Atomic Lock

from atomicity import AtomicLock

# Create an atomic boolean with an initial value of False
atom = AtomicLock( False)

# Perform atomic operations
atom.store(True)
value = atom.acquire()
previous_value = atom.release()

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

  • The atomicity library is heavily dependent on and inspired by the Rust std::sync::atomic module.

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

atomicity-0.0.3.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distributions

atomicity-0.0.3-cp310-none-win_amd64.whl (130.1 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

atomicity-0.0.3-cp310-cp310-manylinux_2_34_x86_64.whl (229.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.34+ x86-64

atomicity-0.0.3-cp310-abi3-manylinux_2_34_x86_64.whl (228.8 kB view hashes)

Uploaded CPython 3.10+ manylinux: glibc 2.34+ x86-64

Supported by

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