Commit 43a7ff78 authored by Tim Peters's avatar Tim Peters

get_transaction(), free_transaction(): Recent removal of default arg

tricks left name thread undefined at runtime.  Repair that.  Plus
add comments, use meaningful variable names, stop pretending we can run
on a system without threads, and don't use "id" (a builtin name) as a
local vrbl name.
parent b6eb4ae8
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
############################################################################## ##############################################################################
"""Transaction management """Transaction management
$Id: Transaction.py,v 1.52 2003/10/02 22:11:28 jeremy Exp $ $Id: Transaction.py,v 1.53 2003/10/02 22:48:07 tim_one Exp $
""" """
import sys import sys
from thread import get_ident as _get_ident
from zLOG import LOG, ERROR, PANIC, INFO, BLATHER, WARNING from zLOG import LOG, ERROR, PANIC, INFO, BLATHER, WARNING
from ZODB.POSException import ConflictError, TransactionError from ZODB.POSException import ConflictError, TransactionError
...@@ -453,39 +454,26 @@ information on the error that lead to this problem. ...@@ -453,39 +454,26 @@ information on the error that lead to this problem.
############################################################################ ############################################################################
# install get_transaction: # install get_transaction:
try: # Map thread ident to its Transaction instance.
import thread _tid2tran = {}
except: # Get Transaction associated with current thread; if none, create a
_t = Transaction(None) # new Transaction and return it.
def get_transaction():
def get_transaction(): tid = _get_ident()
return _t result = _tid2tran.get(tid)
if result is None:
def free_transaction(): _tid2tran[tid] = result = Transaction(tid)
_t.__init__() return result
else: # Forget whatever Transaction (if any) is associated with current thread.
_t = {} def free_transaction():
tid = _get_ident()
def get_transaction():
id = thread.get_ident()
t = _t.get(id, None)
if t is None:
_t[id] = t = Transaction(id)
return t
def free_transaction():
id = thread.get_ident()
try: try:
del _t[id] del _tid2tran[tid]
except KeyError: except KeyError:
pass pass
del thread
del _t
import __builtin__ import __builtin__
__builtin__.get_transaction=get_transaction __builtin__.get_transaction = get_transaction
del __builtin__ del __builtin__
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment