2013-03-18 74 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。如果您使用任何其他数据库,则不应发生代码段中的注释所提示的错误。