Skip to main content

k3txutil

Action-CI Documentation Status Package

A collection of helper functions to implement transactional operations.

k3txutil is a component of pykit3 project: a python3 toolkit set.

Name

txutil

Status

This library is considered production ready.

Description

A collection of helper functions to implement transactional operations.

Exceptions

CASConflict

syntax: CASConflict()

User should raise this exception when a CAS conflict detect in a user defined set function.

Install

pip install k3txutil

Synopsis

import threading

import k3txutil


class Foo:
    def __init__(self):
        self.lock = threading.RLock()
        self.val = 0
        self.ver = 0

    def _get(self, db, key, **kwargs):
        # db, key == 'dbname', 'mykey'
        with self.lock:
            return self.val, self.ver

    def _set(self, db, key, val, prev_stat, **kwargs):
        # db, key == 'dbname', 'mykey'
        with self.lock:
            if prev_stat != self.ver:
                raise k3txutil.CASConflict(prev_stat, self.ver)

            self.val = val
            self.ver += 1

    def test_cas(self):
        for curr in k3txutil.cas_loop(
            self._get,
            self._set,
            args=(
                "dbname",
                "mykey",
            ),
        ):
            curr.v += 2

        print((self.val, self.ver))  # (2, 1)


"""
while True:
    curr_val, stat = getter(key="mykey")
    new_val = curr_val + ':foo'
    try:
        setter(new_val, stat, key="mykey")
    except CASConflict:
        continue
    else:
        break

#`cas_loop` simplifies the above workflow to:
for curr in k3txutil.cas_loop(getter, setter, args=("mykey", )):
    curr.v += ':foo'
"""

Author

Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Copyright and License

The MIT License (MIT)

Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Metadata

Release files for k3txutil 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for k3txutil 0.1.8
File Size Uploaded Provenance Actions
k3txutil-0.1.8.tar.gz 6.0 kB Without provenance Details for k3txutil-0.1.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for k3txutil 0.1.8
File Interpreter ABI Platform Actions
k3txutil-0.1.8-py3-none-any.whl Python 3 none any Details for k3txutil-0.1.8-py3-none-any.whl

Total release size: 11.7 kB

Release files / k3txutil-0.1.8.tar.gz

Download URL k3txutil-0.1.8.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8bbabe50bd88e882373256c16964727149381ebf4461fdaa9a2438559bd26ec6
BLAKE2b-256 checksum
How to use checksums
688af36cef48af82d18f190b4d6cfef4b42ea832d455034ad94f68d51f1ec9e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / k3txutil-0.1.8-py3-none-any.whl

Download URL k3txutil-0.1.8-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
493598e2b165fece1cde0791e141aa46310fb55af1b0da6d40efd88377c1c0b3
BLAKE2b-256 checksum
How to use checksums
31305df5bcd783da36477109e7d65a733d097b39c2da73e581efe87d107305df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for k3txutil 0.1.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page