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
标题: os.getpriority() and os.setpriority()
类型: enhancement Stage: patch review
Components: Extension Modules Versions: Python 3.3
process
状态: closed Resolution: fixed
Dependencies: 后续:
分配给: giampaolo.rodola 抄送列表: christian.heimes, georg.brandl, giampaolo.rodola, loewis, orsenthil, pitrou, rosslagerwall
优先级: normal 关键字: 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.

文件
文件名 上传时间 Description 编辑
getsetpriority.patch giampaolo.rodola, 2010-12-28 01:47
Messages (12)
msg124751 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) 日期: 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) 日期: 2010-12-28 01:47
Forgot to attach the patch.
msg124763 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) 日期: 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) 日期: 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) 日期: 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) 日期: 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) 日期: 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) 日期: 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) 日期: 2011-02-25 21:00
Misc/NEWS updated in r88609.
msg129474 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) 日期: 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) 日期: 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) 日期: 2011-02-26 06:40
Indeed.
历史
日期 用户 动作 参数
2022-04-11 14:57:10admin修改github: 54993
2011-02-26 06:40:26pitrou修改状态: open -> closed
抄送: loewis, georg.brandl, orsenthil, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
消息: + msg129504
2011-02-26 06:34:39orsenthil修改抄送: + orsenthil
消息: + msg129501
2011-02-26 00:11:08pitrou修改状态: closed -> open
抄送: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
消息: + msg129474
2011-02-25 21:00:27giampaolo.rodola修改抄送: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
消息: + msg129427
2011-02-25 20:58:43giampaolo.rodola修改状态: open -> closed

消息: + msg129426
resolution: fixed
抄送: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
2011-01-10 20:02:45pitrou修改抄送: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
stage: patch review
2011-01-10 17:55:27loewis修改抄送: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
消息: + msg125908
2011-01-10 09:44:30giampaolo.rodola修改抄送: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
消息: + msg125887
2010-12-28 10:32:04loewis修改抄送: loewis, georg.brandl, pitrou, giampaolo.rodola, christian.heimes, rosslagerwall
消息: + msg124780
2010-12-28 10:18:26georg.brandl修改抄送: + georg.brandl
消息: + msg124778
2010-12-28 05:36:19rosslagerwall修改抄送: + rosslagerwall
消息: + msg124763

components: + Extension Modules
type: enhancement
2010-12-28 02:04:50giampaolo.rodola修改抄送: + christian.heimes
2010-12-28 01:47:08giampaolo.rodola修改文件: + getsetpriority.patch
抄送: loewis, pitrou, giampaolo.rodola
消息: + msg124752
2010-12-28 01:46:49giampaolo.rodola创建