且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

数据库的Python / Django轮询有内存泄漏

更新时间:2023-02-13 22:06:18

您需要定期重置Django保留用于调试目的的查询列表。通常,它会在每次请求后清除,但是由于您的应用程序不是基于请求的,因此您需要手动执行此操作:

You need to regularly reset a list of queries that Django keeps for debugging purposes. Normally it is cleared after every request, but since your application is not request based, you need to do this manually:

from django import db

db.reset_queries()






另请参见:


See also:

  • "Debugging Django memory leak with TrackRefs and Guppy" by Mikko Ohtamaa:


Django为
调试目的
(connection.queries)跟踪所有查询。此列表已在HTTP请求结束时重置

但是在独立模式下,没有
请求。因此,您需要在每个
工作周期之后手动将
重置为查询列表

Django keeps track of all queries for debugging purposes (connection.queries). This list is reseted at the end of HTTP request. But in standalone mode, there are no requests. So you need to manually reset to queries list after each working cycle


  • 为什么Django泄漏内存?在Django FAQ中-讨论了
    关于将 DEBUG 设置为 False 的问题重要,而
    关于使用 db.reset_queries()清除查询列表,
    在像您这样的应用程序中很重要。

  • "Why is Django leaking memory?" in Django FAQ - it talks both about setting DEBUG to False, which is always important, and about clearing the list of queries using db.reset_queries(), important in applications like yours.