当前位置: 首页>>代码示例>>Python>>正文


Python os.getpriority方法代码示例

本文整理汇总了Python中os.getpriority方法的典型用法代码示例。如果您正苦于以下问题:Python os.getpriority方法的具体用法?Python os.getpriority怎么用?Python os.getpriority使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.getpriority方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_set_get_priority

# 需要导入模块: import os [as 别名]
# 或者: from os import getpriority [as 别名]
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 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_os.py

示例2: test_nice

# 需要导入模块: import os [as 别名]
# 或者: from os import getpriority [as 别名]
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 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:42,代码来源:test_process.py

示例3: nice

# 需要导入模块: import os [as 别名]
# 或者: from os import getpriority [as 别名]
def nice(self):
        return os.getpriority(os.PRIO_PROCESS, self.tpid) 
开发者ID:Nefelim4ag,项目名称:Ananicy,代码行数:4,代码来源:ananicy.py

示例4: test_nice

# 需要导入模块: import os [as 别名]
# 或者: from os import getpriority [as 别名]
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 
开发者ID:giampaolo,项目名称:psutil,代码行数:45,代码来源:test_process.py


注:本文中的os.getpriority方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。