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


Python resource.RLIMIT_NPROC属性代码示例

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


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

示例1: test_preexec_fork_failure

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_NPROC [as 别名]
def test_preexec_fork_failure(self):
        # The internal code did not preserve the previous exception when
        # re-enabling garbage collection
        try:
            from resource import getrlimit, setrlimit, RLIMIT_NPROC
        except ImportError as err:
            self.skipTest(err)  # RLIMIT_NPROC is specific to Linux and BSD
        limits = getrlimit(RLIMIT_NPROC)
        [_, hard] = limits
        setrlimit(RLIMIT_NPROC, (0, hard))
        self.addCleanup(setrlimit, RLIMIT_NPROC, limits)
        try:
            subprocess.call([sys.executable, '-c', ''],
                            preexec_fn=lambda: None)
        except BlockingIOError:
            # Forking should raise EAGAIN, translated to BlockingIOError
            pass
        else:
            self.skipTest('RLIMIT_NPROC had no effect; probably superuser') 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:21,代码来源:test_subprocess.py

示例2: report_resource_limits

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_NPROC [as 别名]
def report_resource_limits(logger: logging.Logger) -> None:
    resources = [
        ('CPU time (seconds)', resource.RLIMIT_CPU),
        ('Heap size (bytes)', resource.RLIMIT_DATA),
        ('Num. process', resource.RLIMIT_NPROC),
        ('Num. files', resource.RLIMIT_NOFILE),
        ('Address space', resource.RLIMIT_AS),
        ('Locked address space', resource.RLIMIT_MEMLOCK)
    ]
    resource_limits = [
        (name, resource.getrlimit(res)) for (name, res) in resources
    ]
    resource_s = '\n'.join([
        '* {}: {}'.format(res, lim) for (res, lim) in resource_limits
    ])
    logger.info("resource limits:\n%s", indent(resource_s, 2)) 
开发者ID:squaresLab,项目名称:BugZoo,代码行数:18,代码来源:util.py

示例3: test_preexec_fork_failure

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_NPROC [as 别名]
def test_preexec_fork_failure(self):
        # The internal code did not preserve the previous exception when
        # re-enabling garbage collection
        try:
            from resource import getrlimit, setrlimit, RLIMIT_NPROC
        except ImportError as err:
            self.skipTest(err)  # RLIMIT_NPROC is specific to Linux and BSD
        limits = getrlimit(RLIMIT_NPROC)
        [_, hard] = limits
        setrlimit(RLIMIT_NPROC, (0, hard))
        self.addCleanup(setrlimit, RLIMIT_NPROC, limits)
        # Forking should raise EAGAIN, translated to BlockingIOError
        with self.assertRaises(BlockingIOError):
            subprocess.call([sys.executable, '-c', ''],
                            preexec_fn=lambda: None) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:17,代码来源:test_subprocess.py

示例4: __find_and_set_higer_system_limits

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_NPROC [as 别名]
def __find_and_set_higer_system_limits(self):
        resource = get_resource_lib()
        if not resource:
            logger.info('System resource package is not available, cannot increase system limits')
            return
        for (res, res_name) in [(resource.RLIMIT_NPROC, 'number of process/threads'), (resource.RLIMIT_NOFILE, 'number of open files')]:
            self.__find_and_set_higer_system_limit(res, res_name) 
开发者ID:naparuba,项目名称:opsbro,代码行数:9,代码来源:launcher.py

示例5: test_number_processes

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_NPROC [as 别名]
def test_number_processes(self):
        nprocs = self.soft_limit(resource.RLIMIT_NPROC, 1, 65535)
        prlimit = processutils.ProcessLimits(number_processes=nprocs)
        self.check_limit(prlimit, 'RLIMIT_NPROC', nprocs) 
开发者ID:openstack,项目名称:oslo.concurrency,代码行数:6,代码来源:test_processutils.py

示例6: thread_ulimit

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_NPROC [as 别名]
def thread_ulimit():
    import resource
    (x, y) = resource.getrlimit(resource.RLIMIT_NPROC)
    resource.setrlimit(
        resource.RLIMIT_NPROC,
        (x - 1000, y)
    )
    yield
    resource.setrlimit(resource.RLIMIT_NPROC, (x, y)) 
开发者ID:Netflix-Skunkworks,项目名称:jvmquake,代码行数:11,代码来源:test_java_opts.py

示例7: thread_ulimit

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_NPROC [as 别名]
def thread_ulimit():
    import resource
    (x, y) = resource.getrlimit(resource.RLIMIT_NPROC)
    resource.setrlimit(
        resource.RLIMIT_NPROC,
        (32768, y)
    )
    print("\nProcess limit after fixture: {}\n".format(
        resource.getrlimit(resource.RLIMIT_NPROC))
    )
    yield
    resource.setrlimit(resource.RLIMIT_NPROC, (x, y)) 
开发者ID:Netflix-Skunkworks,项目名称:jvmquake,代码行数:14,代码来源:test_basic_ooms.py

示例8: _set_ulimit

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_NPROC [as 别名]
def _set_ulimit():
    """Limit resources usage for the current process and/or its children.

    Refer to https://docs.python.org/2.7/library/resource.html
    """
    customized_limits = {
        resource.RLIMIT_NOFILE: 1024,
        resource.RLIMIT_NPROC: 128,
        # TODO(lxkong): 50M by default, need to be configurable in future.
        resource.RLIMIT_FSIZE: 524288000
    }
    for t, soft in customized_limits.items():
        _, hard = resource.getrlimit(t)
        resource.setrlimit(t, (soft, hard)) 
开发者ID:openstack,项目名称:qinling,代码行数:16,代码来源:server.py

示例9: _set_ulimit

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_NPROC [as 别名]
def _set_ulimit():
    """Limit resources usage for the current process and/or its children.

    Refer to https://docs.python.org/2.7/library/resource.html
    """
    customized_limits = {
        resource.RLIMIT_NOFILE: 1024,
        resource.RLIMIT_NPROC: 128,
        # TODO(lxkong): 50M by default, need to be configurable in future.
        resource.RLIMIT_FSIZE: 524288000
    }
    for t, soft in list(customized_limits.items()):
        _, hard = resource.getrlimit(t)
        resource.setrlimit(t, (soft, hard)) 
开发者ID:openstack,项目名称:qinling,代码行数:16,代码来源:server.py

示例10: setProcessLimits

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIMIT_NPROC [as 别名]
def setProcessLimits(x):
        # This is called after fork and before exec. Any messages
        # printed here will look like the program that we are calling
        # printed them out.

        #print("pre switch user")
        if switchUser:
            if os.geteuid() != 0:
                print("We can't switch to a different user if this script is not run as root.")
                exit(1)
            # If we are supposed to switch to a different user account to do the grading
            if os.geteuid() == 0:
                os.setreuid(autograderUid,autograderUid)
            if os.geteuid() == 0:
                print("Still root after trying to switch to autograder user?")
                exit(1)
        else:
            # If we are not switching to a different user, make sure that we don't run as root.
            if os.geteuid() == 0:
                print("Halting. Do not run submitted programs as root.")
                exit(1)
                
        #print("post switch user")
        
        #print("Preexec start")
        if os.setpgrp() == -1:  # put all processes in the same process group so we can kill it and all children it creates.
            print("Failed to set process group!")
        #print("Preexec middle")

        def limitHelper(limitType, limit):
            # limit is a string referring to a previously set environment variable.
            if limit in os.environ:
                limit = int(os.environ[limit])
                (soft, hard) = resource.getrlimit(limitType)
                #print("soft %d, hard %d, requested %d\n" % (soft, hard, limit))
                if hard > 0 and limit > hard:
                    limit = hard
                resource.setrlimit(limitType, (limit, limit))

        limitHelper(resource.RLIMIT_NPROC, "ULIMIT_NPROC")
        limitHelper(resource.RLIMIT_AS, "ULIMIT_AS")
        limitHelper(resource.RLIMIT_DATA, "ULIMIT_DATA") 
开发者ID:skuhl,项目名称:autograder,代码行数:44,代码来源:autograder.py


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