linux - Python resource module not work -


(forgive poor english, not native)

i tried python resource module limit child process.

it seems setting rlimit_cpu can limit amount of cputime, others rlimit_rss didn't work @ all.

for example, use following script call child.py, , set rss limit (1024, 1024):

import os import sys import resource import subprocess  def setlimits():     resource.setrlimit(resource.rlimit_rss, (1024, 1024))  p = subprocess.popen(["./child.py"], preexec_fn=setlimits) print(p.wait()) 

child.py:

#!/usr/bin/env python3 import resource  print("rss limit: ", resource.getrlimit(resource.rlimit_rss)) a=[] while true:     a.append(1) # deadloop, until eat memory 

child process print "rss limit: (1024, 1024)" , continue run until killed. can see child.py eating memory rlimit_rss didn't work.

my os latest archlinux (2.6.39 kernel), , python ver3.2.

according documentation setrlimit(), rlimit_rss has no effect in linux 2.4.30 , later. also, counts memory marked madvise():

rlimit_rss
specifies limit (in pages) of process's resident set (the number of virtual pages resident in ram). limit has effect in linux 2.4.x, x < 30, , there affects calls madvise() specifying madv_willneed.

so, if want limit processes way, you'll have run 2.4 kernel , hack python interpreter calls madvise() on allocated memory, have unexpected side-effects.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -