伪事务处理
功能
对于一组函数,如果执行过程中发生异常, 按照反向的调用顺序依次调用对应的逆过程
栗子
from pytransaction import Transaction
def test1(*args, **kwargs):
print('test1 running..', args, kwargs)
def test2(*args, **kwargs):
print('test2 running...', args, kwargs)
raise ValueError('oops, exception occurs')
def rollback(*args, **kwargs):
print('rolling back...', args, kwargs)
try:
with Transaction() as t:
t.run(test1, rollback, args=(1,2), kwargs={'arg3':3}, rargs=('a', 'b'), rkwargs={'t':'tt'})
t.run(test1, rollback, kwargs={'arg3':3})
t.run(test1, rollback, args=(4,), kwargs={'a':'aa'}, rargs=(5,6), rkwargs='same')
t.run(test2, rollback, args=('stop here',), rargs='same')
t.run(test1, rollback, args=('will not run'))
except Exception as e:
print('handle exceptions here')
raise e
注意
因为逆向操作也可能会失败,因此不能完全保证事务一定得到处理
Metadata
Release files for pytransaction 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytransaction-1.0.0.tar.gz | 1.9 kB | Without provenance | Details for pytransaction-1.0.0.tar.gz |
Release files / pytransaction-1.0.0.tar.gz
| Download URL | pytransaction-1.0.0.tar.gz |
|---|---|
| Size | 1.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65fb2f8a9374c9d7a5cf054d18f19e71ae01d3bc0ec2b4cdc9405053d5a4feb0
|
|
BLAKE2b-256 checksum How to use checksums |
151b113afb1f5cd0a2f140ea59906fb485fffd4d927da3c683f08065b6533d58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.13.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
|
Security for pytransaction 1.0.0
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.