當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。