classification
Title: resource.setrlimit() should raise PermissionError
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: giampaolo.rodola
Priority: normal Keywords: patch

Created on 2019-10-15 07:34 by giampaolo.rodola, last changed 2019-10-15 16:12 by giampaolo.rodola.

Pull Requests
URL Status Linked Edit
PR 16804 open giampaolo.rodola, 2019-10-15 16:11
Messages (2)
msg354701 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2019-10-15 07:34
>>> import resource
    >>> high = 300 * 1024 * 1024
    >>> resource.setrlimit(resource.RLIMIT_MEMLOCK, (high, high))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: not allowed to raise maximum limit
    >>> 

Internally EPERM is translated into ValueError (should have been PermissionError). resource.prlimit(), on the other hand, is not affected (correctly raises PermissionError):

    >>> resource.prlimit(os.getpid(), resource.RLIMIT_MEMLOCK, (high, high))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    PermissionError: [Errno 1] Operation not permitted


It seems 'ValueError' was used in order to provide a more informative error message, but IMO it was a bad call.
Proposal is to change this in 3.9 only, and document it under whatsnew/porting.
msg354741 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2019-10-15 16:12
It turns out there is a similar precedent which was solved in the same way: issue18787.
History
Date User Action Args
2019-10-15 16:12:16giampaolo.rodolasetmessages: + msg354741
2019-10-15 16:11:08giampaolo.rodolasetkeywords: + patch
stage: patch review
pull_requests: + pull_request16360
2019-10-15 07:34:20giampaolo.rodolacreate