我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用psutil.HIGH_PRIORITY_CLASS。
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: try: first_nice = p.nice() p.nice(1) self.assertEqual(p.nice(), 1) # 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
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)
def attach(self, root_process): self.process = root_process if self.high_priority: self.logger.info('Setting server process to high priority') self.process.nice(psutil.HIGH_PRIORITY_CLASS) root_process.nice(psutil.HIGH_PRIORITY_CLASS)
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
def __init__(self, html, app, hub, window_size, debug=False): QMainWindow.__init__(self) self.app = app self.hub = hub self.debug = debug self.html = html self.url = "file:///" \ + os.path.join(self.app.property("ResPath"), "www/").replace('\\', '/') self.is_first_load = True self.view = web_core.QWebView(self) if not self.debug: self.view.setContextMenuPolicy(qt_core.Qt.NoContextMenu) self.view.setCursor(qt_core.Qt.ArrowCursor) self.view.setZoomFactor(1) self.setWindowTitle(APP_NAME) self.icon = self._getQIcon('sumokoin_icon_64.png') self.setWindowIcon(self.icon) self.setCentralWidget(self.view) self.setFixedSize(window_size) self.center() if sys.platform == 'win32': psutil.Process().nice(psutil.HIGH_PRIORITY_CLASS)