Python os.getpriority() Examples

The following are 7 code examples of os.getpriority(). 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 os , or try the search function .
Example #1
Source File: test_os.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #2
Source File: test_os.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
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 
Example #3
Source File: test_os.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #4
Source File: test_process.py    From vnpy_crypto with MIT License 5 votes vote down vote up
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 
Example #5
Source File: test_process.py    From jarvis with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #6
Source File: ananicy.py    From Ananicy with GNU General Public License v3.0 5 votes vote down vote up
def nice(self):
        return os.getpriority(os.PRIO_PROCESS, self.tpid) 
Example #7
Source File: test_process.py    From psutil with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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