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


Python psutil.HIGH_PRIORITY_CLASS屬性代碼示例

本文整理匯總了Python中psutil.HIGH_PRIORITY_CLASS屬性的典型用法代碼示例。如果您正苦於以下問題:Python psutil.HIGH_PRIORITY_CLASS屬性的具體用法?Python psutil.HIGH_PRIORITY_CLASS怎麽用?Python psutil.HIGH_PRIORITY_CLASS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在psutil的用法示例。


在下文中一共展示了psutil.HIGH_PRIORITY_CLASS屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_nice

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import HIGH_PRIORITY_CLASS [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

示例2: setHighPriority

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import HIGH_PRIORITY_CLASS [as 別名]
def setHighPriority(self):
        import psutil
        import platform
        p = psutil.Process(os.getpid())
        OS = platform.system()
        if (OS == "Darwin") or (OS == "Linux"):
            p.nice(5)
        elif OS == "Windows":
            p.nice(psutil.HIGH_PRIORITY_CLASS) 
開發者ID:erikliland,項目名稱:pyMHT,代碼行數:11,代碼來源:tracker.py

示例3: set_priority

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import HIGH_PRIORITY_CLASS [as 別名]
def set_priority(level, pid=None):
    """Set the priority/nice of the application.
    
    Numbers may be used (in the style of Linux from -20 (high) to 19 (low),
    or as text, such as 'belownormal' or 'realtime'.
    """
    process = psutil.Process(pid)
    try:
        level = level.lower().replace(' ', '')
        
        if level == 'realtime':
            process.nice(psutil.REALTIME_PRIORITY_CLASS)
        elif level == 'high':
            process.nice(psutil.HIGH_PRIORITY_CLASS)
        elif level == 'abovenormal':
            process.nice(psutil.ABOVE_NORMAL_PRIORITY_CLASS)
        elif level == 'normal':
            process.nice(psutil.NORMAL_PRIORITY_CLASS)
        elif level == 'belownormal':
            process.nice(psutil.BELOW_NORMAL_PRIORITY_CLASS)
        if level == 'low':
            process.nice(psutil.IDLE_PRIORITY_CLASS)
            
    except AttributeError:
        if level < -13:
            process.nice(psutil.REALTIME_PRIORITY_CLASS)
        elif -13 <= level < -7:
            process.nice(psutil.HIGH_PRIORITY_CLASS)
        elif -7 <= level < 0:
            process.nice(psutil.ABOVE_NORMAL_PRIORITY_CLASS)
        elif 0 <= level < 7:
            process.nice(psutil.NORMAL_PRIORITY_CLASS)
        elif 7 <= level < 12:
            process.nice(psutil.BELOW_NORMAL_PRIORITY_CLASS)
        elif 13 <= level:
            process.nice(psutil.IDLE_PRIORITY_CLASS) 
開發者ID:Peter92,項目名稱:MouseTracks,代碼行數:38,代碼來源:__init__.py

示例4: request_priority_execution

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import HIGH_PRIORITY_CLASS [as 別名]
def request_priority_execution():
    gc.disable()
    sys.setcheckinterval(999999999)
    if sys.version_info > (3, 0, 0):
        sys.setswitchinterval(1000)
    p = psutil.Process(os.getpid())
    try:
        if platform.system() == "Windows":
            p.nice(psutil.HIGH_PRIORITY_CLASS)
        else:
            p.nice(10)
    except psutil.AccessDenied:
        pass

    return p 
開發者ID:StorjOld,項目名稱:pyp2p,代碼行數:17,代碼來源:lib.py

示例5: test_nice

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import HIGH_PRIORITY_CLASS [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


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