小编dsl*_*dsl的帖子

Mysql + django异常:"命令不同步;你现在无法运行此命令"

通过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
Run Code Online (Sandbox Code Playgroud)

我还不能可靠地重现它,也无法追踪导致它的底层代码.

我在某些地方使用原始游标,遵循以下模式:

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])
Run Code Online (Sandbox Code Playgroud)

在某些地方,我立即将光标重用于另一个查询execute()/ fetchall()模式.有时我没有.

我还在某些地方使用原始管理器查询.

我没有明确关闭游标,但我不相信我应该.

除此之外:我没有使用任何存储过程,没有init_command参数,也没有在我在这里发布的其他答案中指出的任何其他内容.

任何有关如何调试的想法或建议将不胜感激.

mysql django mysql-python amazon-rds

6
推荐指数
1
解决办法
3203
查看次数

标签 统计

amazon-rds ×1

django ×1

mysql ×1

mysql-python ×1