Skip to main content

PyZas!: A Python library for atomic integer operations

Project description

PyZas!: A Python library for atomic integer operations

PyZas is a Python library designed for performing atomic integer operations with the speed and efficiency of a zas! (Inspired by the sudden impact sound "zas" spanish onomatopoeia)). PyZas ensures your calculations are executed atomically and safely. Perfect for scenarios requiring quick, thread-safe manipulations.

Installation

You can install PyZas via pip:

pip install pyzas

Usage

The PyZas module implements the following atomic types:

  • AtomicInt: An atomic int type
  • AtomicLong: An atomic 64-bytes int type
  • AtomicULong: An atomic 64-bytes unsigned int type

The three types implement the following functions:

  • free_lock_level() -> int: Determines if the atomic object is implemented lock-free
  • load() -> int: Reads a value from an atomic object
  • store(int): Stores a value in an atomic object
  • exchange(int) -> int: Atomically replaces the value in an atomic object
  • fetch_add(int) -> int: Performs atomic addition
  • fetch_sub(int) -> int: Performs atomic subtraction
  • compare_exchange(int, int) -> int: Swaps a value with an atomic object if the old value is what is expected, otherwise reads the old value

Module also implements AtomicFlag with support for spinlock:

  • test_and_set() -> bool: sets an atomic flag to true and returns the old value
  • clear(): Sets the atomic_flag to false
  • spin_lock(): Causes a thread trying to acquire a lock to simply wait in a loop ("spin")
  • spin_unlock(): Releases the lock

For more details:

help(pyzas)

Example

import pyzas

n = pyzas.AtomicInt(0)
n.fetch_add(1)
print(n.load())

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

pyzas-1.0.tar.gz (42.1 kB view details)

Uploaded Source

Built Distributions

pyzas-1.0-cp313-cp313td-manylinux_2_31_x86_64.whl (41.3 kB view details)

Uploaded CPython 3.13td manylinux: glibc 2.31+ x86-64

pyzas-1.0-cp313-cp313td-manylinux_2_31_aarch64.whl (68.2 kB view details)

Uploaded CPython 3.13td manylinux: glibc 2.31+ ARM64

pyzas-1.0-cp313-cp313td-macosx_13_0_x86_64.whl (19.5 kB view details)

Uploaded CPython 3.13td macOS 13.0+ x86-64

File details

Details for the file pyzas-1.0.tar.gz.

File metadata

  • Download URL: pyzas-1.0.tar.gz
  • Upload date:
  • Size: 42.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.10.4 Windows/10

File hashes

Hashes for pyzas-1.0.tar.gz
Algorithm Hash digest
SHA256 7acaa6a97e24d9c9d2e9ce9219eb47a25c1a18b817ba80c2412ebaf9951e2ede
MD5 0de4465680fcaa6b1acd84dda0b9b856
BLAKE2b-256 f70bdeb0797536a8d86d728f7614b815ed066c3d95437ecac19bd19913468cc0

See more details on using hashes here.

File details

Details for the file pyzas-1.0-cp313-cp313td-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for pyzas-1.0-cp313-cp313td-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 1330587ecf65cdfb8c43bbf1e745c5d7006f0fb3c07dc4d97be47d6308dc2020
MD5 258689c4ec695026c7078bc38ae76a0d
BLAKE2b-256 52420c79bcc0a484973d392cc76e40969d076385b0746b618a565f60300cb8b0

See more details on using hashes here.

File details

Details for the file pyzas-1.0-cp313-cp313td-manylinux_2_31_aarch64.whl.

File metadata

File hashes

Hashes for pyzas-1.0-cp313-cp313td-manylinux_2_31_aarch64.whl
Algorithm Hash digest
SHA256 6adf53f1141cc4bb1b17f3eb64c2ec397eed0ffd0dc1a7e3107346c0c3d409d4
MD5 24c30d8133ea8ee24d6a3f4ed7547d64
BLAKE2b-256 7258f83043eac7eed2d30bb994c91ff6e80f34aaa403241b51d7d4b1b3942b16

See more details on using hashes here.

File details

Details for the file pyzas-1.0-cp313-cp313td-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for pyzas-1.0-cp313-cp313td-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 b6ebb0ef72683fed1c3db3388aab5b3fb607785faa735f314000b3022818c6e8
MD5 9a1dadb51dba2e297b415a1723acc0d0
BLAKE2b-256 4e167835752db15d10a31896f8483283bb03c93c58c1ae1791f26eea7fe69930

See more details on using hashes here.

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