resource.prlimit was added in Python 3.4, but PyPy doesn't have it. This PR adds it.
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
setrlimit(). It also combines the functionality of
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
lib_pypy/_resource_build.pyis 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.)
setrlimit()tests are fairly thin (and comments in the testing code admit as much). I added some more extensive tests for
prlimit(), but I'm not sure if those are too restrictive and might cause breakage on some systems. (Or should they be more extensive?)
resource.prlimit()doesn't allow passing
limitsargument; the only way to do get the resource limits without changing them is to omit the
limitsargument altogether. My current implementation treats
limits=Nonethe same as if it were omitted altogether; should that be changed to match CPython's behavior?
- 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
- 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.