通过gunicorn运行django到RDS (AWS mysql),我在gunicorn日志中看到这个错误:
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
参数,也没有在我在这里看到的其他答案中指示的任何其他内容。
对于如何调试的任何想法或建议将不胜感激。
查看https://code.djangoproject.com/ticket/17289
你需要这样做:
while cursor.nextset() is not None:
if verbose:
print "rows modified %s" % cursor.rowcount