How can you force a memory limit in Django WSGI apps?
apache, django, memory, memory-management, mod-wsgi
Solution
Resource memory limits aren't implemented on most platforms even though C API definitions exist. As such, mod_wsgi doesn't try to implement such restrictions. If PHP is doing it, is is able to do so by virtue that that it is a more constrained and controlled environment than Python.
The only portable way is to have a separate daemon process running which runs 'ps' or uses '/proc' to monitor memory usage of processes and then send a SIGINT signal to those which go over some predefined value.
UPDATE
Version 3.4 of mod_wsgi supports options for daemon mode that may be able to restrict memory usage. See:
- http://code.google.com/p/modwsgi/wiki/ChangesInVersion0304
Whether they work depends on the operating system you are using.
Problem
I want my app to throw an `MemoryError` when its usage goes over 1GB. I'm running in WSGI daemon mode. I see 3 places the memory limit could be: - apache.conf - wsgi somewhere - django configuration but I can't find the right config options. In PHP you can do this with : `php_value memory_limit 1GB` in your `apache.conf`