Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.getpriority() and os.setpriority() #54993

Closed
giampaolo opened this issue Dec 28, 2010 · 12 comments
Closed

os.getpriority() and os.setpriority() #54993

giampaolo opened this issue Dec 28, 2010 · 12 comments
Assignees
Labels
extension-modules C modules in the Modules dir type-feature A feature request or enhancement

Comments

@giampaolo
Copy link
Contributor

BPO 10784
Nosy @loewis, @birkenfeld, @orsenthil, @pitrou, @giampaolo, @tiran
Files
  • getsetpriority.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/giampaolo'
    closed_at = <Date 2011-02-26.06:40:26.507>
    created_at = <Date 2010-12-28.01:46:49.093>
    labels = ['extension-modules', 'type-feature']
    title = 'os.getpriority() and os.setpriority()'
    updated_at = <Date 2011-02-26.06:40:26.506>
    user = 'https://github.com/giampaolo'

    bugs.python.org fields:

    activity = <Date 2011-02-26.06:40:26.506>
    actor = 'pitrou'
    assignee = 'giampaolo.rodola'
    closed = True
    closed_date = <Date 2011-02-26.06:40:26.507>
    closer = 'pitrou'
    components = ['Extension Modules']
    creation = <Date 2010-12-28.01:46:49.093>
    creator = 'giampaolo.rodola'
    dependencies = []
    files = ['20177']
    hgrepos = []
    issue_num = 10784
    keywords = ['patch']
    message_count = 12.0
    messages = ['124751', '124752', '124763', '124778', '124780', '125887', '125908', '129426', '129427', '129474', '129501', '129504']
    nosy_count = 7.0
    nosy_names = ['loewis', 'georg.brandl', 'orsenthil', 'pitrou', 'giampaolo.rodola', 'christian.heimes', 'rosslagerwall']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue10784'
    versions = ['Python 3.3']

    @giampaolo
    Copy link
    Contributor Author

    After having implemented a similar thing in psutil ( http://code.google.com/p/psutil/issues/detail?id=142 ) I decided to contribute a patch for Python which exposes getpriority() and setpriority() POSIX calls in the os module.

    They can be used to get/set process niceness/priority in a fashion similar to os.nice() but extended to *all* processes instead of just os.getpid():
    http://linux.die.net/man/2/setpriority

    @giampaolo giampaolo self-assigned this Dec 28, 2010
    @giampaolo
    Copy link
    Contributor Author

    Forgot to attach the patch.

    @rosslagerwall
    Copy link
    Mannequin

    rosslagerwall mannequin commented Dec 28, 2010

    Patch looks good, just one thing:

    In setpriority(), it should be possible to use the Py_RETURN_NONE; macro instead of INCREFing manually.

    @rosslagerwall rosslagerwall mannequin added extension-modules C modules in the Modules dir type-feature A feature request or enhancement labels Dec 28, 2010
    @birkenfeld
    Copy link
    Member

    Looks good. Would there be a point in making any of the parameters optional?

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Dec 28, 2010

    Looks good. Would there be a point in making any of the parameters optional?

    No. The API should look exactly as it does on the system level. Anybody
    calling these functions should know how call them.

    @giampaolo
    Copy link
    Contributor Author

    Question: should Py_BEGIN/END_ALLOW_THREADS be used around getpriority() and setpriority() calls? It's still not clear to me when to use them exactly.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jan 10, 2011

    You should use begin/end allow threads when the system call might block. To get an indication, trace through the kernel code of some system; my guess is that these are typically non-blocking (i.e. return immediately) - but I might be wrong.

    @giampaolo
    Copy link
    Contributor Author

    Committed in r88608 including Py_RETURN_NONE and Py_BEGIN/END_ALLOW_THREADS changes.

    @giampaolo
    Copy link
    Contributor Author

    Misc/NEWS updated in r88609.

    @pitrou
    Copy link
    Member

    pitrou commented Feb 26, 2011

    ======================================================================
    ERROR: test_set_get_priority (test.test_os.ProgramPriorityTests)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/home/buildbot/buildarea/3.x.ochtman-gentoo-amd64/build/Lib/test/test_os.py", line 1283, in test_set_get_priority
        os.setpriority(os.PRIO_PROCESS, os.getpid(), base)
    OSError: [Errno 13] Permission denied
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/home/buildbot/buildarea/3.x.ochtman-gentoo-amd64/build/Lib/test/test_os.py", line 1285, in test_set_get_priority
        if err.errno != errno.EACCESS:
    AttributeError: 'module' object has no attribute 'EACCESS'

    @pitrou pitrou reopened this Feb 26, 2011
    @orsenthil
    Copy link
    Member

    On Sat, Feb 26, 2011 at 12:11:10AM +0000, Antoine Pitrou wrote:

    if err.errno != errno.EACCESS:
    

    AttributeError: 'module' object has no attribute 'EACCESS'

    That was one 'S' too many. Should be errno.EACCES
    Looks like Antoine has fixed it in r88627.

    @pitrou
    Copy link
    Member

    pitrou commented Feb 26, 2011

    Indeed.

    @pitrou pitrou closed this as completed Feb 26, 2011
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants