Python子进程限制

时间:2012-03-28 22:19:45

标签: python process fork limits

我想在Python中创建一个进程(可能是子进程和Popen),它应该具有有限的CPU时间,有限的子进程和内存带宽。我无法找到办法做到这一点。 resource.setrlimit似乎不起作用。

我的代码是:

import os
import sys
import resource
import subprocess
import signal


def setlimits():
    os.seteuid(65534) # Has to run as root user in order to be able to setuid
    resource.setrlimit(resource.RLIMIT_CPU, (1, 1))
    resource.setrlimit(resource.RLIMIT_FSIZE, (500, 500))
    resource.setrlimit(resource.RLIMIT_NPROC, (80, 80))

p = subprocess.Popen( ["./exec.out"] , preexec_fn=setlimits )

0 个答案:

没有答案