避免 OpenERP 审计跟踪错误
我想通过安装audittrail模块来管理OpenERP用户的活动。
创建一些规则后(定义将监视哪个用户、哪个对象和哪个活动(创建、更新..))。我更新了产品以查看其是否有效。
当我尝试更新产品时,出现系统错误。看到日志,我明白
[2010-08-31 12:53:35,042] 光标未显式关闭
[2010-08-31 12:53:35,043] 光标创建于 /home/pilgrim/working/sources/addons/audittrail/audittrail.py:204
这是导致错误的行
cr = pooler.get_db(db).cursor()
看看 sql_db.py,我得到了这样的评论:
def __del__(self):
if not self.__closed:
# Oops. 'self' has not been closed explicitly.
# The cursor will be deleted by the garbage collector,
# but the database connection is not put back into the connection
# pool, preventing some operation on the database like dropping it.
# This can also lead to a server overload.
msg = "Cursor not closed explicitly\n" \
"Cursor was created at %s:%s" % self.__caller
log(msg, netsvc.LOG_WARNING)
self.close()
既然我是 Python 新手,我不知道如何克服这个问题?
有什么提示可以克服这个问题吗?
感谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看源代码以了解正在发生的事情非常重要。
但从您发布的内容来看,前一个光标似乎没有明确关闭。
我建议您破解audittrail.py以找到您在哪里创建光标以及在哪里关闭它们。一个典型的问题是异常处理不正确,导致代码跳过正常关闭。
尝试在有问题的游标操作周围放置 try、 except 和 finally 子句。这应该可以帮助你解决这个问题。
t would be important to see the source code to understand whats going on.
But from what you have posted it looks like the previous cursor was not closed explicitly.
I would suggest that you hack audittrail.py to find where ever you are creating the cursor and where ever you close them. A typical issue arises in incorrect handling of exceptions, causing code to jump over normal closure.
Try placing a try, except and finally clause around the questionable cursor operation. That should help you to get around the problem.
我想我找到了答案。
看例子
call a()
是正常的。好的。
尝试另一个示例(代码摘自audittrail.py)
看到do_something_with_db的实现尝试打开游标(可以称为连接)但当前游标没有显式关闭。
所以解决方案很简单:传递当前的 cr
现在错误就消失了。
@Don Kirkby:是的,我们应该尝试一下……最后
I think I find the answer.
See an example
call a()
It's normal. OK.
Try another example ( code extract from audittrail.py)
Seeing that the implementation of do_something_with_db trying to open the cursor ( can be called connection) but the current one is not explicitly closed.
So the solution is simple: Pass the current cr around
Now the error's gone.
@Don Kirkby: Yes, we should experiment with try...finally
您可以在调试器中运行 OpenERP,例如 PyDev 插件 .org/" rel="nofollow noreferrer">Eclipse?我发现这是追踪问题的最有效方法。我没有使用审计跟踪模块,但我快速浏览了 源代码,并且光标似乎在
log_fct()
开头附近打开。 (我本希望它报告第 207 行,您运行的是哪个版本?)以下是我认为的相关代码:看起来该方法中有多个 return 语句,但每个语句似乎都调用
cr. close()
首先,所以我没有看到任何明显的问题。尝试在调试器中运行它,并在此方法中设置断点。如果这是不可能的,您可以尝试使用如下内容写入日志:更新:
您评论说这种情况发生在重负载下。也许正在引发异常并且游标未关闭。您可以使用
try
...finally
语句以确保光标始终关闭。以下是上面的示例在转换后的外观:Can you run OpenERP in a debugger like the PyDev plug in for Eclipse? I find that the most effective way to track down problems. I haven't used the audit trail module, but I took a quick look at the source code, and it appears that the cursor is being opened near the beginning of
log_fct()
. (I would have expected it to report line 207, which version are you running?) Here's what I think is the relevant code:It looks like there are several return statements in the method, but each one seems to call
cr.close()
first, so I don't see any obvious problems. Try running it in the debugger with a break point in this method. If that's not possible, you can try writing to the log with something like this:Update:
You commented that this happens under heavy load. Perhaps an exception is being thrown and the cursor is not being closed. You could use a
try
...finally
statement to make sure that the cursor is always closed. Here's how the sample above would look after converting it: