本文整理汇总了Python中os.getpriority方法的典型用法代码示例。如果您正苦于以下问题:Python os.getpriority方法的具体用法?Python os.getpriority怎么用?Python os.getpriority使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.getpriority方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set_get_priority
# 需要导入模块: import os [as 别名]
# 或者: from os import getpriority [as 别名]
def test_set_get_priority(self):
base = os.getpriority(os.PRIO_PROCESS, os.getpid())
os.setpriority(os.PRIO_PROCESS, os.getpid(), base + 1)
try:
new_prio = os.getpriority(os.PRIO_PROCESS, os.getpid())
if base >= 19 and new_prio <= 19:
raise unittest.SkipTest(
"unable to reliably test setpriority at current nice level of %s" % base)
else:
self.assertEqual(new_prio, base + 1)
finally:
try:
os.setpriority(os.PRIO_PROCESS, os.getpid(), base)
except OSError as err:
if err.errno != errno.EACCES:
raise
示例2: test_nice
# 需要导入模块: import os [as 别名]
# 或者: from os import getpriority [as 别名]
def test_nice(self):
p = psutil.Process()
self.assertRaises(TypeError, p.nice, "str")
if WINDOWS:
try:
init = p.nice()
if sys.version_info > (3, 4):
self.assertIsInstance(init, enum.IntEnum)
else:
self.assertIsInstance(init, int)
self.assertEqual(init, psutil.NORMAL_PRIORITY_CLASS)
p.nice(psutil.HIGH_PRIORITY_CLASS)
self.assertEqual(p.nice(), psutil.HIGH_PRIORITY_CLASS)
p.nice(psutil.NORMAL_PRIORITY_CLASS)
self.assertEqual(p.nice(), psutil.NORMAL_PRIORITY_CLASS)
finally:
p.nice(psutil.NORMAL_PRIORITY_CLASS)
else:
first_nice = p.nice()
try:
if hasattr(os, "getpriority"):
self.assertEqual(
os.getpriority(os.PRIO_PROCESS, os.getpid()), p.nice())
p.nice(1)
self.assertEqual(p.nice(), 1)
if hasattr(os, "getpriority"):
self.assertEqual(
os.getpriority(os.PRIO_PROCESS, os.getpid()), p.nice())
# XXX - going back to previous nice value raises
# AccessDenied on OSX
if not OSX:
p.nice(0)
self.assertEqual(p.nice(), 0)
except psutil.AccessDenied:
pass
finally:
try:
p.nice(first_nice)
except psutil.AccessDenied:
pass
示例3: nice
# 需要导入模块: import os [as 别名]
# 或者: from os import getpriority [as 别名]
def nice(self):
return os.getpriority(os.PRIO_PROCESS, self.tpid)
示例4: test_nice
# 需要导入模块: import os [as 别名]
# 或者: from os import getpriority [as 别名]
def test_nice(self):
p = psutil.Process()
self.assertRaises(TypeError, p.nice, "str")
init = p.nice()
try:
if WINDOWS:
for prio in [psutil.NORMAL_PRIORITY_CLASS,
psutil.IDLE_PRIORITY_CLASS,
psutil.BELOW_NORMAL_PRIORITY_CLASS,
psutil.REALTIME_PRIORITY_CLASS,
psutil.HIGH_PRIORITY_CLASS,
psutil.ABOVE_NORMAL_PRIORITY_CLASS]:
with self.subTest(prio=prio):
try:
p.nice(prio)
except psutil.AccessDenied:
pass
else:
self.assertEqual(p.nice(), prio)
else:
try:
if hasattr(os, "getpriority"):
self.assertEqual(
os.getpriority(os.PRIO_PROCESS, os.getpid()),
p.nice())
p.nice(1)
self.assertEqual(p.nice(), 1)
if hasattr(os, "getpriority"):
self.assertEqual(
os.getpriority(os.PRIO_PROCESS, os.getpid()),
p.nice())
# XXX - going back to previous nice value raises
# AccessDenied on MACOS
if not MACOS:
p.nice(0)
self.assertEqual(p.nice(), 0)
except psutil.AccessDenied:
pass
finally:
try:
p.nice(init)
except psutil.AccessDenied:
pass