我知道os.nice(20)
设置了linux上的最大nice级别。
但是我不知道其他unix的值(value)(我不关心MS-Win)。
是否有一个我可以从 python 使用的最大nice值的符号值?
首选解决方案:
os.nice(NICE_MAX)
我试图在这里找到解决方案:
- http://docs.python.org/2/library/os.html#os.nice
目录(操作系统)
grep -i Nice/usr/lib64/python/os*.py
最佳答案
我认为最接近我们在这里得到的标准的是 POSIX (IEEE 1003)。实际规范确实为实现留下了范围,但请注意:
If value+{NZERO} is less than the system’s lowest supported nice value, setpriority( ) shall set the nice value to the lowest supported value; if value+{NZERO} is greater than the system’s highest supported nice value, setpriority( ) shall set the nice value to the highest supported value.
因此,如果你只是想要最高的友善,你可以通过它 INT_MAX
,但在 Python 中不容易找到该值。 NZERO
确实提供了边界,但同样很难找到(它在 limits.h
中定义)。
但是,Python 的 os.nice
行为不像 setpriority
- 它增加过程的良好性,并且还返回结果的良好性。因此,如果您只想设置最高的良好度,您可以运行一个 while 循环,直到 os.nice(N)
返回相同的值两次,假设 N 是任何适合 ctypes.c_int
的正值(保证适合 1 到 32767 之间的任何整数)。
关于python - os.nice() 的最大nice值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22532482/