0

I have a Python loop which checks that the available memory is always sufficient at each pass:

import psutil

for e in mylist:
    if psutil.virtual_memory().available:
        raise ValueError
    else:
        # Do some stuff...

In order to add another layer of security when launching my script, I would like to use ulimit -v as well.

I tried running the following to check if psutil will take the ulimit into account, but it does not:

$ ulimit -v 2000000
> import psutil
> psutil.virtual_memory().available

Any idea how I could combine a check inside my script, and put a hard limit on my Ubuntu 18.04 machine ? If possible, I'd like to keep the script code unchanged and rather use something else than ulimit if it exists.

Oriane Nedey
  • 23
  • 1
  • 6

0 Answers0