You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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 commented on Jan 10, 2011
loewismannequin
Mannequin
More actions
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.
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_priorityif err.errno != errno.EACCESS:
AttributeError: 'module' object has no attribute 'EACCESS'
Activity
giampaolo commentedon Dec 28, 2010
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 commentedon Dec 28, 2010
Forgot to attach the patch.
rosslagerwall commentedon 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.
birkenfeld commentedon Dec 28, 2010
Looks good. Would there be a point in making any of the parameters optional?
loewis commentedon Dec 28, 2010
No. The API should look exactly as it does on the system level. Anybody
calling these functions should know how call them.
giampaolo commentedon Jan 10, 2011
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 commentedon 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 commentedon Feb 25, 2011
Committed in r88608 including Py_RETURN_NONE and Py_BEGIN/END_ALLOW_THREADS changes.
giampaolo commentedon Feb 25, 2011
Misc/NEWS updated in r88609.
pitrou commentedon Feb 26, 2011
======================================================================
ERROR: test_set_get_priority (test.test_os.ProgramPriorityTests)
----------------------------------------------------------------------
orsenthil commentedon Feb 26, 2011
On Sat, Feb 26, 2011 at 12:11:10AM +0000, Antoine Pitrou wrote:
That was one 'S' too many. Should be errno.EACCES
Looks like Antoine has fixed it in r88627.
pitrou commentedon Feb 26, 2011
Indeed.