根據此(http://djangosnippets.org/snippets/926/)代碼段,連接關閉在句柄。但它是一種舊代碼。我需要關閉數據庫連接命令[django]
在django 1.4中,我們必須關閉連接嗎?我通過django代碼查看,但我無法找到關閉連接的代碼。
如果django關閉連接,它在哪裏?
謝謝。
根據此(http://djangosnippets.org/snippets/926/)代碼段,連接關閉在句柄。但它是一種舊代碼。我需要關閉數據庫連接命令[django]
在django 1.4中,我們必須關閉連接嗎?我通過django代碼查看,但我無法找到關閉連接的代碼。
如果django關閉連接,它在哪裏?
謝謝。
隨着片斷指出:
# 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.
但問題是確實在生命週期結束的Django命令密切的聯繫? – 2016-06-16 04:50:50