This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.getpriority() and os.setpriority()
Type: enhancement Stage: patch review
Components: Extension Modules Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: giampaolo.rodola Nosy List: christian.heimes, georg.brandl, giampaolo.rodola, loewis, orsenthil, pitrou, rosslagerwall
Priority: normal Keywords: patch

Created on 2010-12-28 01:46 by giampaolo.rodola, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
getsetpriority.patch giampaolo.rodola, 2010-12-28 01:47
Messages (12)
msg124751 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-12-28 01:46
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
msg124752 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-12-28 01:47
Forgot to attach the patch.
msg124763 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2010-12-28 05:36
Patch looks good, just one thing:

In setpriority(), it should be possible to use the Py_RETURN_NONE; macro instead of INCREFing manually.
msg124778 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-12-28 10:18
Looks good.  Would there be a point in making any of the parameters optional?
msg124780 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-12-28 10:32
> 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.
msg125887 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-01-10 09:44
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.
msg125908 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-01-10 17:55
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.
msg129426 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-02-25 20:58
Committed in r88608 including Py_RETURN_NONE and Py_BEGIN/END_ALLOW_THREADS changes.
msg129427 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2011-02-25 21:00
Misc/NEWS updated in r88609.
msg129474 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-02-26 00:11
======================================================================
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'
msg129501 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-02-26 06:34
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.
msg129504 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-02-26 06:40
Indeed.
History
Date User Action Args
2022-04-11 14:57:10adminsetgithub: 54993
2011-02-26 06:40:26pitrousetstatus: open -> closed
nosy: loewis, georg.brandl, orsenthil, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
messages: + msg129504
2011-02-26 06:34:39orsenthilsetnosy: + orsenthil
messages: + msg129501
2011-02-26 00:11:08pitrousetstatus: closed -> open
nosy: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
messages: + msg129474
2011-02-25 21:00:27giampaolo.rodolasetnosy: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
messages: + msg129427
2011-02-25 20:58:43giampaolo.rodolasetstatus: open -> closed

messages: + msg129426
resolution: fixed
nosy: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
2011-01-10 20:02:45pitrousetnosy: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
stage: patch review
2011-01-10 17:55:27loewissetnosy: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
messages: + msg125908
2011-01-10 09:44:30giampaolo.rodolasetnosy: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
messages: + msg125887
2010-12-28 10:32:04loewissetnosy: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
messages: + msg124780
2010-12-28 10:18:26georg.brandlsetnosy: + georg.brandl
messages: + msg124778
2010-12-28 05:36:19rosslagerwallsetnosy: + rosslagerwall
messages: + msg124763

components: + Extension Modules
type: enhancement
2010-12-28 02:04:50giampaolo.rodolasetnosy: + christian.heimes
2010-12-28 01:47:08giampaolo.rodolasetfiles: + getsetpriority.patch
nosy: loewis, pitrou, giampaolo.rodola
messages: + msg124752
2010-12-28 01:46:49giampaolo.rodolacreate