How to limit memory usage within a python process

后端 未结 1 703
南笙
南笙 2020-12-10 01:25

I run Python 2.7 on a Linux machine with 16GB Ram and 64 bit OS. A python script I wrote can load too much data into memory, which slows the machine down to the point where

相关标签:
1条回答
  • 2020-12-10 02:05

    resource.RLIMIT_VMEM is the resource corresponding to ulimit -v.

    RLIMIT_DATA only affects brk/sbrk system calls while newer memory managers tend to use mmap instead.

    The second thing to note is that ulimit/setrlimit only affects the current process and its future children.

    Regarding the AttributeError: 'module' object has no attribute 'RLIMIT_VMEM' message: the resource module docs mention this possibility:

    This module does not attempt to mask platform differences — symbols not defined for a platform will not be available from this module on that platform.

    According to the bash ulimit source linked to above, it uses RLIMIT_AS if RLIMIT_VMEM is not defined.

    0 讨论(0)
提交回复
热议问题