2012-12-28 41 views
6

通过gunicorn运行Django到RDS(AWS MySQL的),我看到这个错误在我gunicorn日志:MYSQL + Django的例外:“命令不同步,你无法运行此命令现在”

Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in <bound method Cursor.__del__ of <MySQLdb.cursors.Cursor object at 0x690ecd0>> ignored 

我无法可靠地重现它,我也无法追查导致它的底层代码。

我使用的原料光标在一些地方,下面这个模式:

cursor = connections['read_only'].cursor() 
sql = "select username from auth_user;" 
cursor.execute(sql) 
rows = cursor.fetchall() 
usernames = [] 
for row in rows: 
    usernames.append(row[0]) 

在一些地方,我立刻重新使用游标的另一个查询的execute()/使用fetchall()模式。有时候我没有。

我也在一些地方使用原始经理查询。

我没有明确关闭游标,但我不认为我应该。

其他:我没有使用任何存储过程,没有init_command参数,也没有任何东西在我见过张贴在这里其他的答案其他指示。

如何调试的任何意见或建议,将不胜感激。

+0

这是造成异常你比显示在日志中了其他任何实际问题? – Air

+0

[Python,“命令可能不同步;您现在无法运行此命令”]的可能重复(http://stackoverflow.com/questions/11583083/python-commands-out-of-sync-you-cant- run-this-command-now) – e4c5

回答

-3

退房https://code.djangoproject.com/ticket/17289

你需要做的是这样:

while cursor.nextset() is not None: 
    if verbose:               
     print "rows modified %s" % cursor.rowcount 
+0

这个问题根本没有提到存储过程(就像你引用的票据一样)。 –

相关问题