Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
ZODB
Commits
152a3193
Commit
152a3193
authored
Jun 11, 2003
by
Jeremy Hylton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add transact helper.
parent
1c519e6e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
src/ZODB/transact.py
src/ZODB/transact.py
+57
-0
No files found.
src/ZODB/transact.py
0 → 100644
View file @
152a3193
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Tools to simplify transactions within applications."""
from
ZODB.POSException
import
ReadConflictError
,
ConflictError
def
_commit
(
note
):
t
=
get_transaction
()
if
note
:
t
.
note
(
note
)
t
.
commit
()
def
transact
(
f
,
note
=
None
,
retries
=
5
):
"""Returns transactional version of function argument f.
Higher-order function that converts a regular function into
a transactional function. The transactional function will
retry up to retries time before giving up. If note, it will
be added to the transaction metadata when it commits.
The retries occur on ConflictErrors. If some other
TransactionError occurs, the transaction will not be retried.
"""
# XXX deal with ZEO disconnected errors?
def
g
(
*
args
,
**
kwargs
):
while
retries
:
retries
-=
1
try
:
r
=
f
(
*
args
,
**
kwargs
)
except
ReadConflictError
,
msg
:
get_transaction
().
abort
()
if
not
retries
:
raise
continue
try
:
_commit
(
note
)
except
ConflictError
,
msg
:
get_transaction
().
abort
()
if
not
retries
:
raise
continue
return
r
raise
RuntimeError
,
"couldn't commit transaction"
return
g
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment