I am trying to limit the use of RAM with the Python program to half, so it doesn’t completely freeze when all RAM is used, for this I use the following code that does not work, and my laptop is still freezing:
import sys
import resource
def memory_limit():
rsrc = resource.RLIMIT_DATA
soft, hard = resource.getrlimit(rsrc)
soft /= 2
resource.setrlimit(rsrc, (soft, hard))
if __name__ == '__main__':
memory_limit()
try:
main()
except MemoryError:
sys.stderr.write('MAXIMUM MEMORY EXCEEDED')
sys.exit(-1)
I use other functions that I call from a function main.
What am I doing wrong?
Thanks in advance.
PD: I already searched about this and found the code that I installed, but it still does not work ...
source
share