Skip to content

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

Closed

Description

@giampaolo
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']

    Activity

    1. giampaolo commented on Dec 28, 2010

      @giampaolo
      ContributorAuthor

      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

    2. self-assigned this
      on Dec 28, 2010
    3. giampaolo commented on Dec 28, 2010

      @giampaolo
      ContributorAuthor

      Forgot to attach the patch.

    4. rosslagerwall commented on Dec 28, 2010

      rosslagerwallmannequin
      Mannequin

      Patch looks good, just one thing:

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

    5. birkenfeld commented on Dec 28, 2010

      @birkenfeld
      Member

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

    6. loewis commented on Dec 28, 2010

      loewismannequin
      Mannequin

      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.

    7. giampaolo commented on Jan 10, 2011

      @giampaolo
      ContributorAuthor

      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.

    8. loewis commented on Jan 10, 2011

      loewismannequin
      Mannequin

      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.

    9. giampaolo commented on Feb 25, 2011

      @giampaolo
      ContributorAuthor

      Committed in r88608 including Py_RETURN_NONE and Py_BEGIN/END_ALLOW_THREADS changes.

    10. giampaolo commented on Feb 25, 2011

      @giampaolo
      ContributorAuthor

      Misc/NEWS updated in r88609.

    11. pitrou commented on Feb 26, 2011

      @pitrou
      Member

      ======================================================================
      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'
    12. reopened this on Feb 26, 2011
    13. orsenthil commented on Feb 26, 2011

      @orsenthil
      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.

    14. pitrou commented on Feb 26, 2011

      @pitrou
      Member

      Indeed.

    15. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    extension-modulesC modules in the Modules dirtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions