禁用 "remember every SQL query" (Django)

Disable "remember every SQL query" (Django)

我知道这个:

It is also important to remember that when running with DEBUG turned on, Django will remember every SQL query it executes. This is useful when you’re debugging, but it’ll rapidly consume memory on a production server.

来源:https://docs.djangoproject.com/en/dev/ref/settings/#debug

我有一个执行压力测试的 python 脚本。

此脚本使用 django 测试运行器。

它在循环中使用 ORM,在每次迭代中处理越来越多的流量。

如果我的脚本能在任何环境下工作就好了。

我不希望其他开发人员在执行此脚本之前强制 fiddle 使用他们的设置(将 DEBUG 配置为 False)。

有没有办法禁用特定功能 "remember every SQL query"?

您可以尝试使用猴子补丁 BaseDatabaseWrapperqueries_limit 设置为零。否则,您可以让脚本验证调试设置为 False,如果他们尝试在调试设置为 True 的情况下使用它,则显示一条消息,通知他们使用 DEBUG=False python manage.py script.[=14= 运行 它]