k3txutil
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.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| k3txutil-0.1.6.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| k3txutil-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.9 kB
Release files / k3txutil-0.1.6.tar.gz
| Download URL | k3txutil-0.1.6.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5dddcd93a27ebeac68ed758709305ef12e72e6a0c6b60b508f48a9af76c065f7
|
|
BLAKE2b-256 checksum How to use checksums |
b877bcd250516f52c4ed49662f08612df0d93fe2e67275f4864e6614c6e3fef3
|
| 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.6-py3-none-any.whl
| Download URL | k3txutil-0.1.6-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23b54fa6d6b5ab70b2c0c87f31f700d5abf1a6aecf7b9b787bfa1b48e9162656
|
|
BLAKE2b-256 checksum How to use checksums |
8dc352dc7790d6326fb17a209f126939903580139f31ac024ead4d6e91e54ab4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|