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


Python psutil.win_service_iter方法代碼示例

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


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

示例1: get_sids_from_windows

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import win_service_iter [as 別名]
def get_sids_from_windows():
    """return ORACLE_SID ORACLE_HOME list from windows service defs"""
    sids = []

    for _p in psutil.win_service_iter():
        info = _p.as_dict()

        if 'OracleService' in info['name']:
            # print(info)
            # print(info['name'])
            # print(info['binpath'])
            oracle_sid = info['name'].strip('OracleService')
            oracle_home = os.path.dirname(
                os.path.dirname(info['binpath']))
            sids.append([oracle_sid, oracle_home])

    return sids 
開發者ID:ikzelf,項目名稱:zbxdb,代碼行數:19,代碼來源:zbx_alertlog.py

示例2: test_win_service_get_config

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import win_service_iter [as 別名]
def test_win_service_get_config(self):
            name = next(psutil.win_service_iter()).name()
            self.execute(cext.winservice_query_config, name) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:5,代碼來源:test_memory_leaks.py

示例3: test_win_service_get_status

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import win_service_iter [as 別名]
def test_win_service_get_status(self):
            name = next(psutil.win_service_iter()).name()
            self.execute(cext.winservice_query_status, name) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:5,代碼來源:test_memory_leaks.py

示例4: test_win_service_get_description

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import win_service_iter [as 別名]
def test_win_service_get_description(self):
            name = next(psutil.win_service_iter()).name()
            self.execute(cext.winservice_query_descr, name) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:5,代碼來源:test_memory_leaks.py

示例5: test_win_service_get

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import win_service_iter [as 別名]
def test_win_service_get(self):
        name = next(psutil.win_service_iter()).name()

        with self.assertRaises(psutil.NoSuchProcess) as cm:
            psutil.win_service_get(name + '???')
        self.assertEqual(cm.exception.name, name + '???')

        # test NoSuchProcess
        service = psutil.win_service_get(name)
        exc = WindowsError(
            psutil._psplatform.cext.ERROR_SERVICE_DOES_NOT_EXIST, "")
        with mock.patch("psutil._psplatform.cext.winservice_query_status",
                        side_effect=exc):
            self.assertRaises(psutil.NoSuchProcess, service.status)
        with mock.patch("psutil._psplatform.cext.winservice_query_config",
                        side_effect=exc):
            self.assertRaises(psutil.NoSuchProcess, service.username)

        # test AccessDenied
        exc = WindowsError(
            psutil._psplatform.cext.ERROR_ACCESS_DENIED, "")
        with mock.patch("psutil._psplatform.cext.winservice_query_status",
                        side_effect=exc):
            self.assertRaises(psutil.AccessDenied, service.status)
        with mock.patch("psutil._psplatform.cext.winservice_query_config",
                        side_effect=exc):
            self.assertRaises(psutil.AccessDenied, service.username)

        # test __str__ and __repr__
        self.assertIn(service.name(), str(service))
        self.assertIn(service.display_name(), str(service))
        self.assertIn(service.name(), repr(service))
        self.assertIn(service.display_name(), repr(service)) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:35,代碼來源:test_windows.py

示例6: test_win_service_get_config

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import win_service_iter [as 別名]
def test_win_service_get_config(self):
            name = next(psutil.win_service_iter()).name()
            self.execute(lambda: cext.winservice_query_config(name)) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:5,代碼來源:test_memleaks.py

示例7: test_win_service_get_status

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import win_service_iter [as 別名]
def test_win_service_get_status(self):
            name = next(psutil.win_service_iter()).name()
            self.execute(lambda: cext.winservice_query_status(name)) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:5,代碼來源:test_memleaks.py

示例8: test_win_service_get_description

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import win_service_iter [as 別名]
def test_win_service_get_description(self):
            name = next(psutil.win_service_iter()).name()
            self.execute(lambda: cext.winservice_query_descr(name)) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:5,代碼來源:test_memleaks.py

示例9: get_all_dlls_by_service_name

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import win_service_iter [as 別名]
def get_all_dlls_by_service_name(service_name):
    services = list(psutil.win_service_iter())
    for service in services:
        service = service.as_dict()
        if service['status'] != 'started' and service['pid'] is not None:
            get_all_dlls_by_process_pid(service['pid']) 
開發者ID:Josue87,項目名稱:BoomER,代碼行數:8,代碼來源:list_dll_by_pid.py

示例10: ServicesList

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import win_service_iter [as 別名]
def ServicesList(self):
        try:
            results = []
            for service in psutil.win_service_iter():
                try:
                    results.append(service.as_dict())
                except Exception as e:
                    print(str(e))
            result = json.dumps(results)
            return [True, result]
            
        except Exception as e:
            return [False, "Plugin Services Failed, reason: " + str(e)] 
開發者ID:muteb,項目名稱:Hoarder,代碼行數:15,代碼來源:hoarder.py

示例11: test_win_service_iter

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import win_service_iter [as 別名]
def test_win_service_iter(self):
        valid_statuses = set([
            "running",
            "paused",
            "start",
            "pause",
            "continue",
            "stop",
            "stopped",
        ])
        valid_start_types = set([
            "automatic",
            "manual",
            "disabled",
        ])
        valid_statuses = set([
            "running",
            "paused",
            "start_pending",
            "pause_pending",
            "continue_pending",
            "stop_pending",
            "stopped"
        ])
        for serv in psutil.win_service_iter():
            data = serv.as_dict()
            self.assertIsInstance(data['name'], str)
            self.assertNotEqual(data['name'].strip(), "")
            self.assertIsInstance(data['display_name'], str)
            self.assertIsInstance(data['username'], str)
            self.assertIn(data['status'], valid_statuses)
            if data['pid'] is not None:
                psutil.Process(data['pid'])
            self.assertIsInstance(data['binpath'], str)
            self.assertIsInstance(data['username'], str)
            self.assertIsInstance(data['start_type'], str)
            self.assertIn(data['start_type'], valid_start_types)
            self.assertIn(data['status'], valid_statuses)
            self.assertIsInstance(data['description'], str)
            pid = serv.pid()
            if pid is not None:
                p = psutil.Process(pid)
                self.assertTrue(p.is_running())
            # win_service_get
            s = psutil.win_service_get(serv.name())
            # test __eq__
            self.assertEqual(serv, s) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:49,代碼來源:test_windows.py

示例12: test_win_service_get

# 需要導入模塊: import psutil [as 別名]
# 或者: from psutil import win_service_iter [as 別名]
def test_win_service_get(self):
        ERROR_SERVICE_DOES_NOT_EXIST = \
            psutil._psplatform.cext.ERROR_SERVICE_DOES_NOT_EXIST
        ERROR_ACCESS_DENIED = psutil._psplatform.cext.ERROR_ACCESS_DENIED

        name = next(psutil.win_service_iter()).name()
        with self.assertRaises(psutil.NoSuchProcess) as cm:
            psutil.win_service_get(name + '???')
        self.assertEqual(cm.exception.name, name + '???')

        # test NoSuchProcess
        service = psutil.win_service_get(name)
        if PY3:
            args = (0, "msg", 0, ERROR_SERVICE_DOES_NOT_EXIST)
        else:
            args = (ERROR_SERVICE_DOES_NOT_EXIST, "msg")
        exc = WindowsError(*args)
        with mock.patch("psutil._psplatform.cext.winservice_query_status",
                        side_effect=exc):
            self.assertRaises(psutil.NoSuchProcess, service.status)
        with mock.patch("psutil._psplatform.cext.winservice_query_config",
                        side_effect=exc):
            self.assertRaises(psutil.NoSuchProcess, service.username)

        # test AccessDenied
        if PY3:
            args = (0, "msg", 0, ERROR_ACCESS_DENIED)
        else:
            args = (ERROR_ACCESS_DENIED, "msg")
        exc = WindowsError(*args)
        with mock.patch("psutil._psplatform.cext.winservice_query_status",
                        side_effect=exc):
            self.assertRaises(psutil.AccessDenied, service.status)
        with mock.patch("psutil._psplatform.cext.winservice_query_config",
                        side_effect=exc):
            self.assertRaises(psutil.AccessDenied, service.username)

        # test __str__ and __repr__
        self.assertIn(service.name(), str(service))
        self.assertIn(service.display_name(), str(service))
        self.assertIn(service.name(), repr(service))
        self.assertIn(service.display_name(), repr(service)) 
開發者ID:giampaolo,項目名稱:psutil,代碼行數:44,代碼來源:test_windows.py


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