I'm guessing your problem is that you haven't understood that rlimit
s are set per process. If you use os.system
in Python to call ulimit, that is only going to set the ulimit in that newly spawned shell process, which then immediately exits after which nothing has been changed.
What you need to do, instead, is to run ulimit
in the shell that starts your program. The process your program is running in will then inherit that rlimit from the shell.
I do not think there is any way to alter the rlimit of process X from process Y, where X != Y.
EDIT: I'll have to take that last back, at least in case you're running in Linux. There is a Linux-specific syscall prlimit
that allows you to change the rlimits of a different process, and it also does appear to be available in Python's resource
module, though it is undocumented there. See the manpage prlimit(2)
instead; I'd assume that the function available in Python uses the same arguments.