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:
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
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:
Whether they work depends on the operating system you are using.
Use resource.setrlimit()
with resource.RLIMIT_VMEM
.
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