當前位置: 首頁>>代碼示例>>Python>>正文


Python psutil.IOPRIO_CLASS_IDLE屬性代碼示例

本文整理匯總了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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:22,代碼來源:test_process.py

示例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") 
開發者ID:AmesCornish,項目名稱:buttersink,代碼行數:8,代碼來源:Butter.py

示例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) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:43,代碼來源:test_process.py

示例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)) 
開發者ID:thelastpickle,項目名稱:cassandra-medusa,代碼行數:10,代碼來源:backup.py

示例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) 
開發者ID:nixys,項目名稱:nxs-backup,代碼行數:12,代碼來源:general_function.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:46,代碼來源:test_process.py


注:本文中的psutil.IOPRIO_CLASS_IDLE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。