Django using too much memory? Turn off DEBUG=True!
When the Django docs say to turn off DEBUG in settings.py to save memory, they’re not talking peanuts. Over the weekend I imported the largest section of my old blog to my new Django blog, and the command-line script to publish these pages crashed with a MemoryError: “*** error: can't allocate region”.
I ran the script again and watched memory use in top. After a few hundred pages, my 1.5 gigabytes of free memory had dropped to under 10. A quick Google search indicated that the first thing to do when Django has memory problems is turn off DEBUG in settings.py. I did that this morning, and free memory, after scaring me by dropping considerably in the first few minutes, hovered around 1.4 gig for the rest of the process’s life. The Python process, which had grown to over a gigabyte last night, remained at 54 megabytes throughout the upload process.
I’d have to say that DEBUG is meant only for debugging immediate issues and should never be used for long-term development.
More Django
- Django: fix_ampersands and abbreviations
- The fix_ampersands filter will miss some cases where ampersands need to be replaced.
- Custom managers for Django ForeignKeys
- I’ve got one really annoying model for keywords. There’s one category of keywords that, by default, should not show up when used as a ForeignKey for most models. Key word: most.
- Fixing Django 1.2.4’s SuspiciousOperation on filtering
- When you get the message “Filtering by keyword not allowed” in Django 1.2.4, here’s one way to fix it.
- Reusing Django’s filter_horizontal
- Just as with pop-ups, it’s possible to use the built-in JavaScript for filtering multiple-selection popups on custom forms.
- Django formsets and date/time fields
- Date/Time fields in Django formsets appear to have incompatible default values, resulting in forms using them always looking as though they’ve got a new entry when they don’t.
- 25 more pages with the topic Django, and other related pages
More Duh
- minidom self-closes empty SCRIPT tags
- Python’s minidom will self-close empty script tags—as it should. But it turns out that Firefox 3.6 and IE 8 don’t support empty script tags.
- Add nodes to SimpleXMLElement
- If you want to add child nodes in PHP’s SimpleXML, the correct way to do it is to add the node first, then create it.
- No distutils? Install Xcode
- If Distutils is not available on Mac OS X Leopard, install the Xcode developer tools. Also, the upgrade process I followed for upgrading from Mailman 2.1.9 to 2.1.12.
- Django QuerySet Heisenberg gotcha
- Observing a system changes the system. That’s especially true with Django’s QuerySet API.
