Is there some way to limit memory consumption in Python?

Hi Community Python!

feature description

  1. I would like to know if it would be possible to limit the consumption of memory in Python:
  2. PHP has a configuration file where we can limit ram consumption, reference here understanding-php-memory_limit/
  3. PHP memory_limit directive specifies the memory limit that a given application has to run.

content

sample 1
import standard
memory_limit = 256M
sample 2
from memory import config
memory_limit = 256M
sample 3
from config import memory
memory_limit = 256M
1 Like

Have a look at the resource library:

https://docs.python.org/3/library/resource.html

Iā€™m not sure how well it works or whether it does what you want.

2 Likes