2013-03-18 70 views

回答

1

隨着片斷指出:

# Close the DB connection. This is required as a workaround for an 
# edge case in MySQL: if the same connection is used to 
# create tables, load data, and query, the query can return 
# incorrect results. 

從Django的:

So, yes, if you do something to deliberately create lots of connections, 
lot of connections will be created. However, Django closes its connection to the 
database at the end of each request/response cycle, so there is only one connection 
in operation per thread or process handling requests and responses. If you're not 
using the HTTP layer, it's still only one connection per thread of execution and 
you are in complete control of the number of threads you create. 

https://code.djangoproject.com/ticket/9878

+0

但問題是確實在生命週期結束的Django命令密切的聯繫? – 2016-06-16 04:50:50

0

首先聲明:我不是專家(遠非如此)。

反正你引用片段指的是兩張票:在Django票建議關閉連接已被列入裝載固定裝置的代碼(參見行55-60在的Django /核心/管理/命令/ loaddata。 py)。 MySQL門票表明他們身上沒有任何變化。

無論如何,我認爲這取決於你想要做什麼。最重要的是,「連接關閉」修復似乎只是一個MySQL。如果您使用任何其他數據庫,則不應發生代碼段中的註釋所提示的錯誤。