2012-12-28 38 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

這個問題根本沒有提到存儲過程(就像你引用的票據一樣)。 –

相關問題