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 k3txutil
import threading


class Foo(object):

    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.4

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.4
File Size Uploaded
k3txutil-0.1.4.tar.gz 5.4 kB Details

Built distribution (wheel)

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

Total release size: 10.9 kB

Release files / k3txutil-0.1.4.tar.gz

Download URL k3txutil-0.1.4.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c307a16bd5457294123f4ab90e966c1e2e1c746a84eec86d8b338bc665b46896
BLAKE2b-256 checksum
How to use checksums
71da7a0fbe3c543129e85bbc332689b0182fdc77f4e956609e7ebb55fb4f7d58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

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

Download URL k3txutil-0.1.4-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b02eda735bc4792e9c159cb7010e97b2f00a355e566da867c6fde7a5e235c74
BLAKE2b-256 checksum
How to use checksums
3b74a42ae85d4f726c4ab19a7f96ad181ea09efdb67eb458ad36949dd7e91d04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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