def ensure_transactionless(msg=None, transaction_manager=transaction.manager):
"""Make sure the current thread doesn't already have db transaction in process.
:param transaction_manager: TransactionManager to check. Defaults to thread local transaction manager.
"""
txn = transaction_manager._txn
if txn:
if not msg:
msg = "Dangling transction open in transaction.manager. You should not start new one."
transaction_thread = getattr(transaction.manager, "begin_thread", None)
logger.fatal("Transaction state management error. Trying to start TX in thread %s. TX started in thread %s", threading.current_thread(), transaction_thread)
# Destroy the transaction, so if this was a temporary failure in long running process, we don't lock the process up for the good
txn.abort()
raise TransactionAlreadyInProcess(msg)
评论列表
文章目录