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
- 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.
- Multiple Input Fields with multiple inheritance
- We needed to display one TextField as either a TextInput or a Textarea, depending on the value in the field. Multiple inheritance makes it easy, if a bit wonky.
- Django tutorial mostly ready
- My long-promised Django tutorial is pretty much ready. It’s still designed around an in-person tutorial, but you should be able to get started using it even if you’re on your own.
- Django: Beyond the SQL
- Django is a great application framework for Python and web applications. You can use it to greatly speed up your database and application development both on the web and on the command line. This tutorial is currently a very rough draft; it probably won’t be very useful without the assistance of someone who knows Django running the tutorial. If I ever run this tutorial a second time, I’ll probably update it with screenshots to make it more usable for individuals.
- 22 more pages with the topic Django, and other related pages
More Duh
- 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.
