本文整理汇总了Python中psutil.users方法的典型用法代码示例。如果您正苦于以下问题:Python psutil.users方法的具体用法?Python psutil.users怎么用?Python psutil.users使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil
的用法示例。
在下文中一共展示了psutil.users方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_serialization
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def test_serialization(self):
def check(ret):
if json is not None:
json.loads(json.dumps(ret))
a = pickle.dumps(ret)
b = pickle.loads(a)
self.assertEqual(ret, b)
check(psutil.Process().as_dict())
check(psutil.virtual_memory())
check(psutil.swap_memory())
check(psutil.cpu_times())
check(psutil.cpu_times_percent(interval=0))
check(psutil.net_io_counters())
if LINUX and not os.path.exists('/proc/diskstats'):
pass
else:
if not APPVEYOR:
check(psutil.disk_io_counters())
check(psutil.disk_partitions())
check(psutil.disk_usage(os.getcwd()))
check(psutil.users())
示例2: test_users
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def test_users(self):
users = psutil.users()
self.assertNotEqual(users, [])
for user in users:
assert user.name, user
self.assertIsInstance(user.name, str)
self.assertIsInstance(user.terminal, (str, type(None)))
if user.host is not None:
self.assertIsInstance(user.host, (str, type(None)))
user.terminal
user.host
assert user.started > 0.0, user
datetime.datetime.fromtimestamp(user.started)
if WINDOWS or OPENBSD:
self.assertIsNone(user.pid)
else:
psutil.Process(user.pid)
示例3: test_users_mocked
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def test_users_mocked(self):
# Make sure ':0' and ':0.0' (returned by C ext) are converted
# to 'localhost'.
with mock.patch('psutil._pslinux.cext.users',
return_value=[('giampaolo', 'pts/2', ':0',
1436573184.0, True, 2)]) as m:
self.assertEqual(psutil.users()[0].host, 'localhost')
assert m.called
with mock.patch('psutil._pslinux.cext.users',
return_value=[('giampaolo', 'pts/2', ':0.0',
1436573184.0, True, 2)]) as m:
self.assertEqual(psutil.users()[0].host, 'localhost')
assert m.called
# ...otherwise it should be returned as-is
with mock.patch('psutil._pslinux.cext.users',
return_value=[('giampaolo', 'pts/2', 'foo',
1436573184.0, True, 2)]) as m:
self.assertEqual(psutil.users()[0].host, 'foo')
assert m.called
示例4: logged_user
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def logged_user(response):
values = [["NAME", "TERMINAL", "HOST", "STARTED"]]
for user in psutil.users():
values.append([
user[0],
user[1],
user[2],
time_op.timestamp2string(int(user[3]))
])
response["authentication"].append({
"name" : "Who is logged on",
"value" : len(values) - 1,
"values" : values
})
示例5: logged_user
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def logged_user(response):
values = [[Klanguage().to_ts(1135), Klanguage().to_ts(1141), Klanguage().to_ts(1142), Klanguage().to_ts(1143)]]
for user in psutil.users():
values.append([
user[0],
user[1],
user[2],
time_op.timestamp2string(int(user[3]))
])
response["authentication"].append({
"name" : Klanguage().to_ts(1140),
"values" : values
})
示例6: connected_users
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def connected_users(self) -> ConnectedUserResponseList:
"""
Get the list of connected users.
:return: List of :class:`platypush.message.response.system.ConnectUserResponse`.
"""
import psutil
users = psutil.users()
return ConnectedUserResponseList([
ConnectUserResponse(
name=u.name,
terminal=u.terminal,
host=u.host,
started=datetime.fromtimestamp(u.started),
pid=u.pid,
)
for u in users
])
# noinspection PyShadowingBuiltins
示例7: check
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def check(self) -> Optional[str]:
for entry in psutil.users():
if (
self._user_regex.fullmatch(entry.name) is not None
and self._terminal_regex.fullmatch(entry.terminal) is not None
and self._host_regex.fullmatch(entry.host) is not None
):
self.logger.debug(
"User %s on terminal %s from host %s " "matches criteria.",
entry.name,
entry.terminal,
entry.host,
)
return (
"User {user} is logged in on terminal {terminal} "
"from {host} since {started}".format(
user=entry.name,
terminal=entry.terminal,
host=entry.host,
started=entry.started,
)
)
return None
示例8: get_sessions
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def get_sessions():
info = '%d user(s) in Total' % len(psutil.users())
for user in psutil.users():
info += '\n%s on %s from %s at %s' % (
user[0], user[1], user[2], time.strftime("%Y-%m-%d %H:%M", time.localtime(user[3])))
return info
示例9: test_users
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def test_users(self):
self.execute(psutil.users)
示例10: test_procinfo
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def test_procinfo(self):
self.assert_stdout('procinfo.py', str(os.getpid()))
# can't find users on APPVEYOR or TRAVIS
示例11: test_users
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def test_users(self):
# Duplicate of test_system.py. Keep it anyway.
for user in psutil.users():
self.assertIsInstance(user.name, str)
self.assertIsInstance(user.terminal, (str, type(None)))
self.assertIsInstance(user.host, (str, type(None)))
self.assertIsInstance(user.pid, (int, type(None)))
# ===================================================================
# --- Featch all processes test
# ===================================================================
示例12: setUp
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def setUp(self):
if POSIX:
import pwd
import grp
users = pwd.getpwall()
groups = grp.getgrall()
self.all_uids = set([x.pw_uid for x in users])
self.all_usernames = set([x.pw_name for x in users])
self.all_gids = set([x.gr_gid for x in groups])
示例13: test_nic_names
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def test_nic_names(self):
output = sh("ifconfig -a")
for nic in psutil.net_io_counters(pernic=True).keys():
for line in output.split():
if line.startswith(nic):
break
else:
self.fail(
"couldn't find %s nic in 'ifconfig -a' output\n%s" % (
nic, output))
# can't find users on APPVEYOR or TRAVIS
示例14: test_users
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def test_users(self):
out = sh("who")
lines = out.split('\n')
users = [x.split()[0] for x in lines]
terminals = [x.split()[1] for x in lines]
self.assertEqual(len(users), len(psutil.users()))
for u in psutil.users():
self.assertIn(u.name, users)
self.assertIn(u.terminal, terminals)
示例15: test_users
# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def test_users(self):
# Duplicate of test_system.py. Keep it anyway.
for user in psutil.users():
self.assertIsInstance(user.name, str)
self.assertIsInstance(user.terminal, (str, type(None)))
self.assertIsInstance(user.host, (str, type(None)))
self.assertIsInstance(user.pid, (int, type(None)))