我需要关闭数据库连接命令[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