本文整理匯總了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)