当前位置: 首页>>代码示例>>Python>>正文


Python psutil.users方法代码示例

本文整理汇总了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()) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:test_misc.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:test_system.py

示例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 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:21,代码来源:test_linux.py

示例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
	}) 
开发者ID:turingsec,项目名称:marsnake,代码行数:19,代码来源:authentication.py

示例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
	}) 
开发者ID:turingsec,项目名称:marsnake,代码行数:18,代码来源:security_audit_implement.py

示例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 
开发者ID:BlackLight,项目名称:platypush,代码行数:22,代码来源:__init__.py

示例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 
开发者ID:languitar,项目名称:autosuspend,代码行数:25,代码来源:activity.py

示例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 
开发者ID:BennyThink,项目名称:ServerSan,代码行数:8,代码来源:ss-agent.py

示例9: test_users

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import users [as 别名]
def test_users(self):
        self.execute(psutil.users) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:4,代码来源:test_memory_leaks.py

示例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 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:6,代码来源:test_misc.py

示例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
# =================================================================== 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:14,代码来源:test_contracts.py

示例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]) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_contracts.py

示例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 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:14,代码来源:test_posix.py

示例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) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_posix.py

示例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))) 
开发者ID:giampaolo,项目名称:psutil,代码行数:9,代码来源:test_contracts.py


注:本文中的psutil.users方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。