Python psutil.IOPRIO_CLASS_IDLE Examples

The following are 8 code examples of psutil.IOPRIO_CLASS_IDLE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module psutil , or try the search function .
Example #1
Source File: test_process.py    From vnpy_crypto with MIT License 6 votes vote down vote up
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) 
Example #2
Source File: test_process.py    From jarvis with GNU General Public License v2.0 6 votes vote down vote up
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) 
Example #3
Source File: Butter.py    From buttersink with GNU General Public License v3.0 5 votes vote down vote up
def _makeNice(process):
    try:
        ps = psutil.Process(process.pid)
        ps.ionice(psutil.IOPRIO_CLASS_IDLE)
    except AttributeError:
        logger.debug("ionice is not available") 
Example #4
Source File: test_process.py    From psutil with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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) 
Example #5
Source File: backup.py    From cassandra-medusa with Apache License 2.0 5 votes vote down vote up
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)) 
Example #6
Source File: general_function.py    From nxs-backup with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #7
Source File: test_process.py    From vnpy_crypto with MIT License 4 votes vote down vote up
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) 
Example #8
Source File: test_process.py    From jarvis with GNU General Public License v2.0 4 votes vote down vote up
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)