我有一个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
我如何探究这个问题?
答案 0 :(得分:0)
在输入save_email()
之前,似乎发生了错误。如果commit()
中没有rollback()
或process_msg()
指令,则会引发TransactionError。
您可以尝试使用调试器圈出错误:
def process_msg(m):
try:
import pdb # import python debugger
pdb.set_trace() # begin debugging
#....
save_email(u, l, d, t,
[…]
您可以在Python website上找到有关如何使用调试器的信息。