• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python _compat.print_函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中psutil._compat.print_函数的典型用法代码示例。如果您正苦于以下问题:Python print_函数的具体用法?Python print_怎么用?Python print_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了print_函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

def main():
    users = psutil.get_users()
    for user in users:
        print_("%-15s %-15s %s  (%s)" % (
            user.name,
            user.terminal or '-',
            datetime.fromtimestamp(user.started).strftime("%Y-%m-%d %H:%M"),
            user.host))
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:8,代码来源:who.py


示例2: main

def main():
    print_("Network Information\n------")
    # bytes_sent= psutil.network_io_counters().bytes_sent
    # print (bytes2human(bytes_sent))

    # check()
    value = network_all()
    print value
开发者ID:confine-project,项目名称:confine-dist,代码行数:8,代码来源:network.py


示例3: main

def main():
    today_day = datetime.date.today()
    templ = "%-10s %5s %4s %4s %7s %7s %-13s %5s %7s  %s"
    attrs = ['pid', 'cpu_percent', 'memory_percent', 'name', 'cpu_times',
             'create_time', 'memory_info']
    if os.name == 'posix':
        attrs.append('uids')
        attrs.append('terminal')
    print_(templ % ("USER", "PID", "%CPU", "%MEM", "VSZ", "RSS", "TTY",
                    "START", "TIME", "COMMAND"))
    for p in psutil.process_iter():
        try:
            pinfo = p.as_dict(attrs, ad_value='')
        except psutil.NoSuchProcess:
            pass
        else:
            if pinfo['create_time']:
                ctime = datetime.datetime.fromtimestamp(pinfo['create_time'])
                if ctime.date() == today_day:
                    ctime = ctime.strftime("%H:%M")
                else:
                    ctime = ctime.strftime("%b%d")
            else:
                ctime = ''
            cputime = time.strftime("%M:%S",
                                    time.localtime(sum(pinfo['cpu_times'])))
            try:
                user = p.username()
            except KeyError:
                if os.name == 'posix':
                    if pinfo['uids']:
                        user = str(pinfo['uids'].real)
                    else:
                        user = ''
                else:
                    raise
            except psutil.Error:
                user = ''
            if os.name == 'nt' and '\\' in user:
                user = user.split('\\')[1]
            vms = pinfo['memory_info'] and \
                int(pinfo['memory_info'].vms / 1024) or '?'
            rss = pinfo['memory_info'] and \
                int(pinfo['memory_info'].rss / 1024) or '?'
            memp = pinfo['memory_percent'] and \
                round(pinfo['memory_percent'], 1) or '?'
            print_(templ % (user[:10],
                            pinfo['pid'],
                            pinfo['cpu_percent'],
                            memp,
                            vms,
                            rss,
                            pinfo.get('terminal', '') or '?',
                            ctime,
                            cputime,
                            pinfo['name'].strip() or '?'))
开发者ID:601040605,项目名称:ChromeFuzzer,代码行数:56,代码来源:ps.py


示例4: main

def main():
    templ = "%-17s %8s %8s %8s %5s%% %9s  %s"
    print_(templ % ("Device", "Total", "Used", "Free", "Use ", "Type", "Mount"))
    for part in psutil.disk_partitions(all=False):
        usage = psutil.disk_usage(part.mountpoint)
        print_(templ % (part.device,
                        bytes2human(usage.total),
                        bytes2human(usage.used),
                        bytes2human(usage.free),
                        int(usage.percent),
                        part.fstype,
                        part.mountpoint))
开发者ID:alepharchives,项目名称:psutil,代码行数:12,代码来源:disk_usage.py


示例5: main

def main():
    if len(sys.argv) != 2:
        sys.exit("usage: pmap pid")
    p = psutil.Process(int(sys.argv[1]))
    print_("pid=%s, name=%s" % (p.pid, p.name))
    templ = "%-16s %10s  %-7s %s"
    print_(templ % ("Address", "RSS", "Mode", "Mapping"))
    total_rss = 0
    for m in p.get_memory_maps(grouped=False):
        total_rss += m.rss
        print_(templ % (m.addr.split("-")[0].zfill(16), str(m.rss / 1024) + "K", m.perms, m.path))
    print_("-" * 33)
    print_(templ % ("Total", str(total_rss / 1024) + "K", "", ""))
开发者ID:hybridlogic,项目名称:psutil,代码行数:13,代码来源:pmap.py


示例6: test

def test():
    """List info of all currently running processes emulating ps aux
    output.
    """
    import datetime
    from psutil._compat import print_

    today_day = datetime.date.today()
    templ = "%-10s %5s %4s %4s %7s %7s %-13s %5s %7s  %s"
    attrs = ['pid', 'username', 'get_cpu_percent', 'get_memory_percent', 'name',
             'get_cpu_times', 'create_time', 'get_memory_info']
    if os.name == 'posix':
        attrs.append('terminal')
    print_(templ % ("USER", "PID", "%CPU", "%MEM", "VSZ", "RSS", "TTY", "START",
                    "TIME", "COMMAND"))
    for p in sorted(process_iter(), key=lambda p: p.pid):
        try:
            pinfo = p.as_dict(attrs, ad_value='')
        except NoSuchProcess:
            pass
        else:
            if pinfo['create_time']:
                ctime = datetime.datetime.fromtimestamp(pinfo['create_time'])
                if ctime.date() == today_day:
                    ctime = ctime.strftime("%H:%M")
                else:
                    ctime = ctime.strftime("%b%d")
            else:
                ctime = ''
            cputime = time.strftime("%M:%S", time.localtime(sum(pinfo['cpu_times'])))
            user = pinfo['username']
            if os.name == 'nt' and '\\' in user:
                user = user.split('\\')[1]
            vms = pinfo['memory_info'] and \
                  int(pinfo['memory_info'].vms / 1024) or '?'
            rss = pinfo['memory_info'] and \
                  int(pinfo['memory_info'].rss / 1024) or '?'
            memp = pinfo['memory_percent'] and \
                   round(pinfo['memory_percent'], 1) or '?'
            print_(templ % (user[:10],
                            pinfo['pid'],
                            pinfo['cpu_percent'],
                            memp,
                            vms,
                            rss,
                            pinfo.get('terminal', '') or '?',
                            ctime,
                            cputime,
                            pinfo['name'].strip() or '?'))
开发者ID:CaiZhongda,项目名称:psutil,代码行数:49,代码来源:__init__.py


示例7: main

def main():
    templ = "%-17s %8s %8s %8s %5s%% %9s  %s"
    print_(templ % ("Device", "Total", "Used", "Free", "Use ", "Type", "Mount"))
    for part in psutil.disk_partitions(all=False):
        if os.name == 'nt' and 'cdrom' in part.opts:
            # may raise ENOENT if there's no cd-rom in the drive
            continue
        usage = psutil.disk_usage(part.mountpoint)
        print_(templ % (part.device,
                        bytes2human(usage.total),
                        bytes2human(usage.used),
                        bytes2human(usage.free),
                        int(usage.percent),
                        part.fstype,
                        part.mountpoint))
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:15,代码来源:disk_usage.py


示例8: main

def main():
    templ = "%-17s %8s %8s %8s %5s%% %9s  %s"
    print_(templ % ("Device", "Total", "Used", "Free", "Use ", "Type", "Mount"))
    for part in psutil.disk_partitions(all=False):
        if os.name == 'nt':
            if 'cdrom' in part.opts or part.fstype == '':
                # skip cd-rom drives with no disk in it; they may raise
                # ENOENT, pop-up a Windows GUI error for a non-ready
                # partition or just hang.
                continue
        usage = psutil.disk_usage(part.mountpoint)
        print_(templ % (part.device,
                        bytes2human(usage.total),
                        bytes2human(usage.used),
                        bytes2human(usage.free),
                        int(usage.percent),
                        part.fstype,
                        part.mountpoint))
开发者ID:BenningtonCS,项目名称:GFS,代码行数:18,代码来源:disk_usage.py


示例9: main

def main():
    templ = "%-5s %-22s %-22s %-13s %-6s %s"
    print_(templ % (
        "Proto", "Local addr", "Remote addr", "Status", "PID", "Program name"))
    for p in psutil.process_iter():
        name = '?'
        try:
            name = p.name()
            cons = p.connections(kind='inet')
        except psutil.AccessDenied:
            print_(templ % (AD, AD, AD, AD, p.pid, name))
        except psutil.NoSuchProcess:
            continue
        else:
            for c in cons:
                raddr = ""
                laddr = "%s:%s" % (c.laddr)
                if c.raddr:
                    raddr = "%s:%s" % (c.raddr)
                print_(templ % (
                    proto_map[(c.family, c.type)],
                    laddr,
                    raddr,
                    c.status,
                    p.pid,
                    name[:15]))
开发者ID:ztop,项目名称:psutil,代码行数:26,代码来源:netstat.py


示例10: main

def main():
    templ = "%-5s %-30s %-30s %-13s %-6s %s"
    print_(templ % (
        "Proto", "Local address", "Remote address", "Status", "PID",
        "Program name"))
    proc_names = {}
    for p in psutil.process_iter():
        try:
            proc_names[p.pid] = p.name()
        except psutil.Error:
            pass
    for c in psutil.net_connections(kind='inet'):
        laddr = "%s:%s" % (c.laddr)
        raddr = ""
        if c.raddr:
            raddr = "%s:%s" % (c.raddr)
        print_(templ % (
            proto_map[(c.family, c.type)],
            laddr,
            raddr or AD,
            c.status,
            c.pid or AD,
            proc_names.get(c.pid, '?')[:15],
        ))
开发者ID:601040605,项目名称:ChromeFuzzer,代码行数:24,代码来源:netstat.py


示例11: main

def main():
    virt = psutil.virtual_memory()
    swap = psutil.swap_memory()
    templ = "%-7s %10s %10s %10s %10s %10s %10s"
    print_(templ % ('', 'total', 'used', 'free', 'shared', 'buffers', 'cache'))
    print_(templ % ('Mem:', int(virt.total / 1024),
                            int(virt.used / 1024),
                            int(virt.free / 1024),
                            int(getattr(virt, 'shared', 0) / 1024),
                            int(getattr(virt, 'buffers', 0) / 1024),
                            int(getattr(virt, 'cached', 0) / 1024)))
    print_(templ % ('Swap:', int(swap.total / 1024),
                             int(swap.used / 1024),
                             int(swap.free / 1024),
                             '', '', ''))
开发者ID:AshishNamdev,项目名称:mozilla-central,代码行数:15,代码来源:free.py


示例12: main

def main():
    templ = "%-5s %-22s %-22s %-13s %-6s %s"
    print_(templ % ("Proto", "Local addr", "Remote addr", "Status", "PID", "Program name"))
    for p in psutil.process_iter():
        name = "?"
        try:
            name = p.name
            cons = p.get_connections(kind="inet")
        except psutil.AccessDenied:
            print_(templ % (AD, AD, AD, AD, p.pid, name))
        else:
            for c in cons:
                raddr = ""
                laddr = "%s:%s" % (c.local_address)
                if c.remote_address:
                    raddr = "%s:%s" % (c.remote_address)
                print_(templ % (proto_map[(c.family, c.type)], laddr, raddr, str(c.status), p.pid, name[:15]))
开发者ID:hybridlogic,项目名称:psutil,代码行数:17,代码来源:netstat.py


示例13: main

def main():
    print_('MEMORY\n------')
    pprint_ntuple(psutil.virtual_memory())
    print_('\nSWAP\n----')
    pprint_ntuple(psutil.swap_memory())
开发者ID:601040605,项目名称:ChromeFuzzer,代码行数:5,代码来源:meminfo.py


示例14: pprint_ntuple

def pprint_ntuple(nt):
    for name in nt._fields:
        value = getattr(nt, name)
        if name != 'percent':
            value = bytes2human(value)
        print_('%-10s : %7s' % (name.capitalize(), value))
开发者ID:601040605,项目名称:ChromeFuzzer,代码行数:6,代码来源:meminfo.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python _compat.u函数代码示例发布时间:2022-05-25
下一篇:
Python _compat.namedtuple函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap