本文整理汇总了Python中psutil.IOPRIO_CLASS_IDLE属性的典型用法代码示例。如果您正苦于以下问题:Python psutil.IOPRIO_CLASS_IDLE属性的具体用法?Python psutil.IOPRIO_CLASS_IDLE怎么用?Python psutil.IOPRIO_CLASS_IDLE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类psutil
的用法示例。
在下文中一共展示了psutil.IOPRIO_CLASS_IDLE属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ionice_errs
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import IOPRIO_CLASS_IDLE [as 别名]
def test_ionice_errs(self):
sproc = get_test_subprocess()
p = psutil.Process(sproc.pid)
if LINUX:
self.assertRaises(ValueError, p.ionice, 2, 10)
self.assertRaises(ValueError, p.ionice, 2, -1)
self.assertRaises(ValueError, p.ionice, 4)
self.assertRaises(TypeError, p.ionice, 2, "foo")
self.assertRaisesRegex(
ValueError, "can't specify value with IOPRIO_CLASS_NONE",
p.ionice, psutil.IOPRIO_CLASS_NONE, 1)
self.assertRaisesRegex(
ValueError, "can't specify value with IOPRIO_CLASS_IDLE",
p.ionice, psutil.IOPRIO_CLASS_IDLE, 1)
self.assertRaisesRegex(
ValueError, "'ioclass' argument must be specified",
p.ionice, value=1)
else:
self.assertRaises(ValueError, p.ionice, 3)
self.assertRaises(TypeError, p.ionice, 2, 1)
示例2: _makeNice
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import IOPRIO_CLASS_IDLE [as 别名]
def _makeNice(process):
try:
ps = psutil.Process(process.pid)
ps.ionice(psutil.IOPRIO_CLASS_IDLE)
except AttributeError:
logger.debug("ionice is not available")
示例3: test_ionice_linux
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import IOPRIO_CLASS_IDLE [as 别名]
def test_ionice_linux(self):
p = psutil.Process()
if not CI_TESTING:
self.assertEqual(p.ionice()[0], psutil.IOPRIO_CLASS_NONE)
self.assertEqual(psutil.IOPRIO_CLASS_NONE, 0)
self.assertEqual(psutil.IOPRIO_CLASS_RT, 1) # high
self.assertEqual(psutil.IOPRIO_CLASS_BE, 2) # normal
self.assertEqual(psutil.IOPRIO_CLASS_IDLE, 3) # low
init = p.ionice()
try:
# low
p.ionice(psutil.IOPRIO_CLASS_IDLE)
self.assertEqual(tuple(p.ionice()), (psutil.IOPRIO_CLASS_IDLE, 0))
with self.assertRaises(ValueError): # accepts no value
p.ionice(psutil.IOPRIO_CLASS_IDLE, value=7)
# normal
p.ionice(psutil.IOPRIO_CLASS_BE)
self.assertEqual(tuple(p.ionice()), (psutil.IOPRIO_CLASS_BE, 0))
p.ionice(psutil.IOPRIO_CLASS_BE, value=7)
self.assertEqual(tuple(p.ionice()), (psutil.IOPRIO_CLASS_BE, 7))
with self.assertRaises(ValueError):
p.ionice(psutil.IOPRIO_CLASS_BE, value=8)
try:
p.ionice(psutil.IOPRIO_CLASS_RT, value=7)
except psutil.AccessDenied:
pass
# errs
self.assertRaisesRegex(
ValueError, "ioclass accepts no value",
p.ionice, psutil.IOPRIO_CLASS_NONE, 1)
self.assertRaisesRegex(
ValueError, "ioclass accepts no value",
p.ionice, psutil.IOPRIO_CLASS_IDLE, 1)
self.assertRaisesRegex(
ValueError, "'ioclass' argument must be specified",
p.ionice, value=1)
finally:
ioclass, value = init
if ioclass == psutil.IOPRIO_CLASS_NONE:
value = 0
p.ionice(ioclass, value)
示例4: throttle_backup
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import IOPRIO_CLASS_IDLE [as 别名]
def throttle_backup():
"""
Makes sure to only us idle IO for backups
"""
p = psutil.Process(os.getpid())
p.ionice(psutil.IOPRIO_CLASS_IDLE)
p.nice(19)
logging.debug("Process {} was set to use only idle IO and CPU resources".format(p))
示例5: set_prio_process
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import IOPRIO_CLASS_IDLE [as 别名]
def set_prio_process(nice, ionice):
''' The function sets the priority of the current script process.
'''
pid = os.getpid()
p = psutil.Process(pid)
p.nice(nice)
if ionice:
p.ionice(psutil.IOPRIO_CLASS_IDLE)
示例6: test_ionice
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import IOPRIO_CLASS_IDLE [as 别名]
def test_ionice(self):
if LINUX:
from psutil import (IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT,
IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE)
self.assertEqual(IOPRIO_CLASS_NONE, 0)
self.assertEqual(IOPRIO_CLASS_RT, 1)
self.assertEqual(IOPRIO_CLASS_BE, 2)
self.assertEqual(IOPRIO_CLASS_IDLE, 3)
p = psutil.Process()
try:
p.ionice(2)
ioclass, value = p.ionice()
if enum is not None:
self.assertIsInstance(ioclass, enum.IntEnum)
self.assertEqual(ioclass, 2)
self.assertEqual(value, 4)
#
p.ionice(3)
ioclass, value = p.ionice()
self.assertEqual(ioclass, 3)
self.assertEqual(value, 0)
#
p.ionice(2, 0)
ioclass, value = p.ionice()
self.assertEqual(ioclass, 2)
self.assertEqual(value, 0)
p.ionice(2, 7)
ioclass, value = p.ionice()
self.assertEqual(ioclass, 2)
self.assertEqual(value, 7)
finally:
p.ionice(IOPRIO_CLASS_NONE)
else:
p = psutil.Process()
original = p.ionice()
self.assertIsInstance(original, int)
try:
value = 0 # very low
if original == value:
value = 1 # low
p.ionice(value)
self.assertEqual(p.ionice(), value)
finally:
p.ionice(original)