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


Python psutil.RLIMIT_NOFILE属性代码示例

本文整理汇总了Python中psutil.RLIMIT_NOFILE属性的典型用法代码示例。如果您正苦于以下问题:Python psutil.RLIMIT_NOFILE属性的具体用法?Python psutil.RLIMIT_NOFILE怎么用?Python psutil.RLIMIT_NOFILE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在psutil的用法示例。


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

示例1: test_linux_rlimit

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import RLIMIT_NOFILE [as 别名]
def test_linux_rlimit(self):
        ae = self.assertEqual
        hasit = LINUX and get_kernel_version() >= (2, 6, 36)
        ae(hasattr(psutil.Process, "rlimit"), hasit)
        ae(hasattr(psutil, "RLIM_INFINITY"), hasit)
        ae(hasattr(psutil, "RLIMIT_AS"), hasit)
        ae(hasattr(psutil, "RLIMIT_CORE"), hasit)
        ae(hasattr(psutil, "RLIMIT_CPU"), hasit)
        ae(hasattr(psutil, "RLIMIT_DATA"), hasit)
        ae(hasattr(psutil, "RLIMIT_FSIZE"), hasit)
        ae(hasattr(psutil, "RLIMIT_LOCKS"), hasit)
        ae(hasattr(psutil, "RLIMIT_MEMLOCK"), hasit)
        ae(hasattr(psutil, "RLIMIT_NOFILE"), hasit)
        ae(hasattr(psutil, "RLIMIT_NPROC"), hasit)
        ae(hasattr(psutil, "RLIMIT_RSS"), hasit)
        ae(hasattr(psutil, "RLIMIT_STACK"), hasit)

        hasit = LINUX and get_kernel_version() >= (3, 0)
        ae(hasattr(psutil, "RLIMIT_MSGQUEUE"), hasit)
        ae(hasattr(psutil, "RLIMIT_NICE"), hasit)
        ae(hasattr(psutil, "RLIMIT_RTPRIO"), hasit)
        ae(hasattr(psutil, "RLIMIT_RTTIME"), hasit)
        ae(hasattr(psutil, "RLIMIT_SIGPENDING"), hasit) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:25,代码来源:test_contracts.py

示例2: get_process_limits

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import RLIMIT_NOFILE [as 别名]
def get_process_limits(self, pid):
        p = psutil.Process(pid)
        return {
            'RLIMIT_AS': p.rlimit(psutil.RLIMIT_AS),
            'RLIMIT_CORE': p.rlimit(psutil.RLIMIT_CORE),
            'RLIMIT_CPU': p.rlimit(psutil.RLIMIT_CPU),
            'RLIMIT_DATA': p.rlimit(psutil.RLIMIT_DATA),
            'RLIMIT_FSIZE': p.rlimit(psutil.RLIMIT_FSIZE),
            'RLIMIT_LOCKS': p.rlimit(psutil.RLIMIT_LOCKS),
            'RLIMIT_MEMLOCK': p.rlimit(psutil.RLIMIT_MEMLOCK),
            'RLIMIT_MSGQUEUE': p.rlimit(psutil.RLIMIT_MSGQUEUE),
            'RLIMIT_NICE': p.rlimit(psutil.RLIMIT_NICE),
            'RLIMIT_NOFILE': p.rlimit(psutil.RLIMIT_NOFILE),
            'RLIMIT_NPROC': p.rlimit(psutil.RLIMIT_NPROC),
            'RLIMIT_RSS': p.rlimit(psutil.RLIMIT_RSS),
            'RLIMIT_RTPRIO': p.rlimit(psutil.RLIMIT_RTPRIO),
            'RLIMIT_RTTIME': p.rlimit(psutil.RLIMIT_RTTIME),
            'RLIMIT_SIGPENDING': p.rlimit(psutil.RLIMIT_SIGPENDING),
            'RLIMIT_STACK': p.rlimit(psutil.RLIMIT_STACK)
        } 
开发者ID:Jahaja,项目名称:psdash,代码行数:22,代码来源:node.py

示例3: test_rlimit_get

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

示例4: test_rlimit_set

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import RLIMIT_NOFILE [as 别名]
def test_rlimit_set(self):
        limit = thisproc.rlimit(psutil.RLIMIT_NOFILE)
        self.execute(self.proc.rlimit, psutil.RLIMIT_NOFILE, limit)
        self.execute_w_exc(OSError, self.proc.rlimit, -1) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:6,代码来源:test_memory_leaks.py

示例5: test_rlimit_set

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import RLIMIT_NOFILE [as 别名]
def test_rlimit_set(self):
        sproc = get_test_subprocess()
        p = psutil.Process(sproc.pid)
        p.rlimit(psutil.RLIMIT_NOFILE, (5, 5))
        self.assertEqual(p.rlimit(psutil.RLIMIT_NOFILE), (5, 5))
        # If pid is 0 prlimit() applies to the calling process and
        # we don't want that.
        with self.assertRaises(ValueError):
            psutil._psplatform.Process(0).rlimit(0)
        with self.assertRaises(ValueError):
            p.rlimit(psutil.RLIMIT_NOFILE, (5, 5, 5)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:13,代码来源:test_process.py

示例6: test_num_fds

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import RLIMIT_NOFILE [as 别名]
def test_num_fds(self):
        # Note: this fails from time to time; I'm keen on thinking
        # it doesn't mean something is broken
        def call(p, attr):
            args = ()
            attr = getattr(p, name, None)
            if attr is not None and callable(attr):
                if name == 'rlimit':
                    args = (psutil.RLIMIT_NOFILE,)
                attr(*args)
            else:
                attr

        p = psutil.Process(os.getpid())
        failures = []
        ignored_names = ['terminate', 'kill', 'suspend', 'resume', 'nice',
                         'send_signal', 'wait', 'children', 'as_dict',
                         'memory_info_ex']
        if LINUX and get_kernel_version() < (2, 6, 36):
            ignored_names.append('rlimit')
        if LINUX and get_kernel_version() < (2, 6, 23):
            ignored_names.append('num_ctx_switches')
        for name in dir(psutil.Process):
            if (name.startswith('_') or name in ignored_names):
                continue
            else:
                try:
                    num1 = p.num_fds()
                    for x in range(2):
                        call(p, name)
                    num2 = p.num_fds()
                except psutil.AccessDenied:
                    pass
                else:
                    if abs(num2 - num1) > 1:
                        fail = "failure while processing Process.%s method " \
                               "(before=%s, after=%s)" % (name, num1, num2)
                        failures.append(fail)
        if failures:
            self.fail('\n' + '\n'.join(failures)) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:42,代码来源:test_posix.py

示例7: test_rlimit_set

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import RLIMIT_NOFILE [as 别名]
def test_rlimit_set(self):
        p = self.spawn_psproc()
        p.rlimit(psutil.RLIMIT_NOFILE, (5, 5))
        self.assertEqual(p.rlimit(psutil.RLIMIT_NOFILE), (5, 5))
        # If pid is 0 prlimit() applies to the calling process and
        # we don't want that.
        with self.assertRaises(ValueError):
            psutil._psplatform.Process(0).rlimit(0)
        with self.assertRaises(ValueError):
            p.rlimit(psutil.RLIMIT_NOFILE, (5, 5, 5)) 
开发者ID:giampaolo,项目名称:psutil,代码行数:12,代码来源:test_process.py

示例8: test_rlimit

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import RLIMIT_NOFILE [as 别名]
def test_rlimit(self):
        self.execute(lambda: self.proc.rlimit(psutil.RLIMIT_NOFILE)) 
开发者ID:giampaolo,项目名称:psutil,代码行数:4,代码来源:test_memleaks.py

示例9: test_rlimit_set

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import RLIMIT_NOFILE [as 别名]
def test_rlimit_set(self):
        limit = thisproc.rlimit(psutil.RLIMIT_NOFILE)
        self.execute(lambda: self.proc.rlimit(psutil.RLIMIT_NOFILE, limit))
        self.execute_w_exc(OSError, lambda: self.proc.rlimit(-1)) 
开发者ID:giampaolo,项目名称:psutil,代码行数:6,代码来源:test_memleaks.py

示例10: test_rlimit_zombie

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import RLIMIT_NOFILE [as 别名]
def test_rlimit_zombie(self):
        # Emulate a case where rlimit() raises ENOSYS, which may
        # happen in case of zombie process:
        # https://travis-ci.org/giampaolo/psutil/jobs/51368273
        with mock.patch("psutil._pslinux.cext.linux_prlimit",
                        side_effect=OSError(errno.ENOSYS, "")) as m:
            p = psutil.Process()
            p.name()
            with self.assertRaises(psutil.ZombieProcess) as exc:
                p.rlimit(psutil.RLIMIT_NOFILE)
            assert m.called
        self.assertEqual(exc.exception.pid, p.pid)
        self.assertEqual(exc.exception.name, p.name()) 
开发者ID:giampaolo,项目名称:psutil,代码行数:15,代码来源:test_linux.py

示例11: _collect_max_file_descriptor_count

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import RLIMIT_NOFILE [as 别名]
def _collect_max_file_descriptor_count(self, psutil_stats, probe_name, process):
        return process.rlimit(psutil.RLIMIT_NOFILE)[1] 
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:4,代码来源:statistics.py

示例12: getStats

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import RLIMIT_NOFILE [as 别名]
def getStats(self):
        """
        Returns a dictionary containing the server stats and cpu/memory utilization
        """
        # cpu
        if not self.process:
            return {}
        t = os.times()
        cpu_user, cpu_system = 0, 0
        delta_t = t[-1]-self._last_t
        if self._last_t and delta_t > 0:
            cpu_user = (t[0]-self._last_cpu_u)*100./delta_t
            cpu_system = (t[1]-self._last_cpu_s)*100./delta_t
        self._last_cpu_u, self._last_cpu_s, self._last_t = t[0], t[1], t[-1]
        # memory
        m = self.process.get_memory_info()
        d = dict(
            cpu_percent=cpu_user+cpu_system,
            cpu_user_percent=cpu_user,
            cpu_system_percent=cpu_system,
            memory_percent=self.process.get_memory_percent(),
            memory_rss=m.rss, 
            memory_vms=m.vms,
            #open_files=self.process.get_num_fds(),
            #open_files_max=self.process.get_rlimit(psutil.RLIMIT_NOFILE)[1],
            threads=self.process.get_num_threads(),
            connections=self.process.get_connections().__len__(),
        )
        # temp
        if self._calc_temp:
            try:
                d['temp'] = Popen(['/usr/bin/acpi', '-t'], stdout=PIPE).communicate()[0]
            except Exception:
                pass
        # disk
        if self._directory:
            usage = psutil.disk_usage(self._directory)
            d['disk_usage'] = usage.percent
            d['disk_used'] = usage.used
        return d 
开发者ID:ldecicco,项目名称:tapas,代码行数:42,代码来源:util.py

示例13: getProcessResourceUsage

# 需要导入模块: import psutil [as 别名]
# 或者: from psutil import RLIMIT_NOFILE [as 别名]
def getProcessResourceUsage(self, pid_list):
        try:
            results = {}
            for pid in pid_list:
                if pid == 0:
                    continue
                result = {}
                results[str(pid)] = result
                try:
                    proc = psutil.Process(pid)
                except psutil.NoSuchProcess as e:
                    LOG.info("No such process: %s", e.msg)
                    continue
                except:
                    LOG.exception("Process %s:", pid)
                    continue
                result["fileno"] = proc.num_fds()
                try:
                    proc.rlimit
                except AttributeError:
                    max_fileno = -1
                    max_vmsize = -1
                else:
                    max_fileno = proc.rlimit(psutil.RLIMIT_NOFILE)[0]
                    max_vmsize = proc.rlimit(psutil.RLIMIT_AS)[0]
                if max_fileno != -1:
                    result["max_fileno"] = max_fileno

                result["numconnections"] = len(proc.connections('all'))
                result["numfiles"] = len(proc.open_files())

                if max_vmsize != -1:
                    result["max_vmsize"] = str(max_vmsize)
                result["vmsize"] = str(proc.memory_info()[1])
                result["numchildren"] = len(proc.children())
                result["numthreads"] = proc.num_threads()
                result["cpu"] = ",".join(str(x) for x in
                                         [time.time()] +
                                         list(proc.cpu_times()))
                result["diskio"] = ",".join(str(x) for x in
                                            [time.time()] +
                                            list(proc.io_counters()))
            return results
        except:
            LOG.exception("Error")
            return {} 
开发者ID:GambitResearch,项目名称:suponoff,代码行数:48,代码来源:suponoff-monhelper.py


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