本文整理汇总了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
示例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)
示例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)
示例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)
示例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))
示例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))
示例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))
示例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))
示例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'])
示例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)]
示例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)
示例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))