gpt4 book ai didi

Django 事务错误

转载 作者:行者123 更新时间:2023-12-02 05:13:09 25 4
gpt4 key购买 nike

我有一个 cronjob,它处理电子邮件并将它们存储在系统中。一年多来它一直运行良好,但现在突然开始时不时地随机出现这些奇怪的交易错误。

2010-09-02-01:45:11 ERROR Exception occured during mail processing
Traceback (most recent call last):
File "/var/www/example.com/project/scripts/cronjobs.py", line 453, in process_msg
source, email, 'i' if rejection_reason else 'v', rejection_reason)
File "/usr/lib/python2.5/site-packages/django/db/transaction.py", line 267, in _commit_manually
leave_transaction_management()
File "/usr/lib/python2.5/site-packages/django/db/transaction.py", line 77, in leave_transaction_management
raise TransactionManagementError("Transaction managed block ended with pending COMMIT/ROLLBACK")
TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK

它的发生没有任何原因,我也没有任何其他可用的上下文信息。这是我的 process_msg 函数的结构:

@commit_manually
def save_email( u,l, d, t, s, e, status, reason):
try:
# ... bla bla bla ...
commit()
exception, e:
rollback()
raise e

def process_msg(m):
try:
#....
save_email(u, l, d, t
source, email, 'i' if rejection_reason else 'v', rejection_reason)
#....
except Exception, e:
logger.error('Error while processing email', exc_info=True )
return None
else:
return True

我如何探测这个问题?

最佳答案

看起来好像错误发生在输入 save_email() 之前。如果 process_msg() 中没有 commit()rollback() 指令,则会引发 TransactionError。

您可以尝试使用调试器圈出错误:

def process_msg(m):
try:
import pdb # import python debugger
pdb.set_trace() # begin debugging
#....
save_email(u, l, d, t,
[…]

您可以在 Python website 上找到有关如何使用调试器的信息。 .

关于Django 事务错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3635928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com