constrain/limit the memory (RAM) of a process in python for a function via a function decorator on linux
first clone or download the repo and use pip to install
git clone https://github.com/drnhhl/py_limit_memory
cd py_limit_memory
pip install .from py_limit_memory import limit_memory
@limit_memory("10GB") # limit to 10GB
def function_to_limit():
pass
# or
@limit_memory("10%") # limit to 10% of the total RAM
def function_to_limit():
passcode adapted from: stackoverflow