resource.prlimit
was added in Python 3.4, but PyPy doesn't have it. This PR adds it.
Background
For anyone who's unfamiliar with prlimit()
, it's a Linux syscall that allows viewing/manipulating the resource limits of arbitrary processes, not just the current process as with getrlimit()
and setrlimit()
. It also combines the functionality of getrlimit()
and setrlimit()
, allowing you to set new resource limits while also retrieving the previous resource limits.
Note on compatibility: FreeBSD has a very similar interface to manipulate resource limits (it's an undocumented sysctl()
). However, CPython doesn't use that to provide resource.prlimit()
on FreeBSD, so I didn't do that here either.
Things that need to be addressed before this PR can be merged
-
I'm not sure if my use of ffi.cdef()
inlib_pypy/_resource_build.py
is the proper way to add OS-specific headers. (I actually haven't tested that commit yet; I'm currently rebuilding and I'll comment if it fails.) -
The getrlimit()
/setrlimit()
tests are fairly thin (and comments in the testing code admit as much). I added some more extensive tests forprlimit()
, but I'm not sure if those are too restrictive and might cause breakage on some systems. (Or should they be more extensive?) -
CPython's resource.prlimit()
doesn't allow passingNone
for thelimits
argument; the only way to do get the resource limits without changing them is to omit thelimits
argument altogether. My current implementation treatslimits=None
the same as if it were omitted altogether; should that be changed to match CPython's behavior?
Disclaimers
- I'm a new contributor; I'm not sure if what I'm doing meets PyPy's conventions. Mostly I just added the implementation/tests alongside
getrlimit()
/setrlimit()
. - I'm used to Git, and I'm muddling my way through using Mercurial. Please let me know if I did anything wrong setting up this PR.