I am using a custom Django command to generate XML sitemaps for a site with about 3-4 million data entries (./manage.py generate_sitemaps
). This seems to work, but eats way too much memory when DEBUG
is enabled in settings.py.
I usually have the DEBUG
option enabled during development and frequently forget to disable it before starting the sitemap creation. If that happens, the memory starts filling up until the script crashes after about 2-3 hours. Very annoying.
Is there a way to temporarily disable the debug setting for the execution of a Django command? I thought of importing the settings module and overriding the option, but I don't think that'll work.
I think you have a couple of options here:
Import settings and throw an error to remind yourself to turn debug off.
Use the --settings=
and set that equal to a file (e.g. gen_settings.py) file specifically for your generate_sitemaps command where DEBUG=False
. Then create an alias for ./manage.py generate_sitemaps --settings=gen_settings
http://docs.djangoproject.com/en/dev/topics/settings/ warns specifically to not change the settings at runtime
I've used the second option before and it worked fairly well. Better than being annoyed after 2-3 hours =)
I am not really sure it helps you, but you can try:
from django.conf import settings
tmp = settings.DEBUG
settings.DEBUG = False
# some your actions
# ...
# ...
settings.DEBUG = tmp
Alternatively you can use separated settings file and set it in command line like
./manage.py your_command --settings=another_settings.py
And in that another_settings.py:
from .settings import *
DEBUG = False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With