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


Python resource.RLIM_INFINITY属性代码示例

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


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

示例1: _set

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def _set(self):
        self.ulimit = {}
        for key in self.ulimit_options:
            set_value = self.params.get("vt_ulimit_%s" % key)
            if not set_value:
                continue
            # get default ulimit values in tuple (soft, hard)
            self.ulimit[key] = resource.getrlimit(self.ulimit_options[key])

            logging.info("Setting ulimit %s to %s." % (key, set_value))
            if set_value == "ulimited":
                set_value = resource.RLIM_INFINITY
            elif set_value.isdigit():
                set_value = int(set_value)
            else:
                self.test.error("%s is not supported for "
                                "setting ulimit %s" % (set_value, key))
            try:
                resource.setrlimit(self.ulimit_options[key],
                                   (set_value, set_value))
            except ValueError as error:
                self.test.error(str(error)) 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:24,代码来源:test_setup.py

示例2: _EnforceProcessMemoryLimit

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def _EnforceProcessMemoryLimit(self, memory_limit):
    """Enforces a process memory limit.

    Args:
      memory_limit (int): maximum number of bytes the process is allowed
          to allocate, where 0 represents no limit and None a default of
          4 GiB.
    """
    # Resource is not supported on Windows.
    if resource:
      if memory_limit is None:
        memory_limit = 4 * 1024 * 1024 * 1024
      elif memory_limit == 0:
        memory_limit = resource.RLIM_INFINITY

      resource.setrlimit(resource.RLIMIT_DATA, (memory_limit, memory_limit)) 
开发者ID:log2timeline,项目名称:plaso,代码行数:18,代码来源:tools.py

示例3: _reset_file_descriptors

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def _reset_file_descriptors(self):
        """Close open file descriptors and redirect standard streams."""
        if self.close_open_files:
            # Attempt to determine the max number of open files
            max_fds = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
            if max_fds == resource.RLIM_INFINITY:
                # If the limit is infinity, use a more reasonable limit
                max_fds = 2048
        else:
            # If we're not closing all open files, we at least need to
            # reset STDIN, STDOUT, and STDERR.
            max_fds = 3

        for fd in range(max_fds):
            try:
                os.close(fd)
            except OSError:
                # The file descriptor probably wasn't open
                pass

        # Redirect STDIN, STDOUT, and STDERR to /dev/null
        devnull_fd = os.open(os.devnull, os.O_RDWR)
        os.dup2(devnull_fd, 0)
        os.dup2(devnull_fd, 1)
        os.dup2(devnull_fd, 2) 
开发者ID:jnrbsn,项目名称:daemonocle,代码行数:27,代码来源:core.py

示例4: preexec_fn

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def preexec_fn():
    resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY)) 
开发者ID:dobin,项目名称:ffw,代码行数:4,代码来源:servermanager.py

示例5: setupEnvironment

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def setupEnvironment(config):
    """
    Prepare the environment before the server is started.

    For example asan options, working directory, ASLR and ulimit.
    Note that for honggfuzz mode, most of this is ignored.
    """
    # Silence warnings from the ptrace library
    #logging.getLogger().setLevel(logging.ERROR)

    # Most important is to set log_path so we have access to the asan logs
    asanOpts = ""
    asanOpts += "color=never:verbosity=0:leak_check_at_exit=false:"
    asanOpts += "abort_on_error=true:log_path=" + config["temp_dir"] + "/asan"
    os.environ["ASAN_OPTIONS"] = asanOpts

    # Tell Glibc to abort on heap corruption but not dump a bunch of output
    os.environ["MALLOC_CHECK_"] = "2"

    # Check ASLR status
    if "ignore_aslr_status" in config and config["ignore_aslr_status"] is False:
        aslrStatusFile = "/proc/sys/kernel/randomize_va_space"
        d = ""
        with open(aslrStatusFile, "r") as f:
            d = f.read()

            if "disable_aslr_check" not in config and d is not "0":
                logging.error("ASLR Enabled, please disable it:")
                logging.error(" echo 0 | sudo tee /proc/sys/kernel/randomize_va_space")
                sys.exit(1)

    # set resources
    if 'handle_corefiles' in config and config['handle_corefiles']:
        resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))

    # set working directory
    os.chdir(config["target_dir"]) 
开发者ID:dobin,项目名称:ffw,代码行数:39,代码来源:targetutils.py

示例6: get_maxfd

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def get_maxfd():
    maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
    if (maxfd == resource.RLIM_INFINITY):
        maxfd = MAXFD
    return maxfd 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:util.py

示例7: get_max_fileno

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def get_max_fileno(default: int=2048):
    """Return the maximum number of open file descriptors."""
    limit = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
    if limit == resource.RLIM_INFINITY:
        return default
    return limit 
开发者ID:edgedb,项目名称:edgedb,代码行数:8,代码来源:lib.py

示例8: __init__

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def __init__(self,nvim):
        Base.__init__(self, nvim)
        self._snippet_engine = nvim.vars['cm_completed_snippet_engine']

        # workaround for #62
        try:
            import resource
            import psutil
            mem = psutil.virtual_memory()
            resource.setrlimit(resource.RLIMIT_DATA, (mem.total/3, resource.RLIM_INFINITY))
        except Exception as ex:
            logger.exception("set RLIMIT_DATA failed. %s", ex)
            pass 
开发者ID:roxma,项目名称:nvim-completion-manager,代码行数:15,代码来源:cm_jedi.py

示例9: _autoclose_files

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def _autoclose_files(shielded=None, fallback_limit=1024):
    ''' Automatically close any open file descriptors.
    
    shielded is iterable of file descriptors.
    '''
    # Process shielded.
    shielded = default_to(shielded, [])
    
    # Figure out the maximum number of files to try to close.
    # This returns a tuple of softlimit, hardlimit; the hardlimit is always
    # greater.
    softlimit, hardlimit = resource.getrlimit(resource.RLIMIT_NOFILE)
    
    # If the hard limit is infinity, we can't iterate to it.
    if hardlimit == resource.RLIM_INFINITY:
        # Check the soft limit. If it's also infinity, fallback to guess.
        if softlimit == resource.RLIM_INFINITY:
            fdlimit = fallback_limit
            
        # The soft limit is finite, so fallback to that.
        else:
            fdlimit = softlimit
            
    # The hard limit is not infinity, so prefer it.
    else:
        fdlimit = hardlimit
    
    # Skip fd 0, 1, 2, which are used by stdin, stdout, and stderr
    # (respectively)
    ranges_to_close = _make_range_tuples(
        start = 3,
        stop = fdlimit,
        exclude = shielded
    )
    for start, stop in ranges_to_close:
        # How nice of os to include this for us!
        os.closerange(start, stop) 
开发者ID:Muterra,项目名称:py_daemoniker,代码行数:39,代码来源:_daemonize_unix.py

示例10: get_maximum_file_descriptors

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def get_maximum_file_descriptors():
    """ Return the maximum number of open file descriptors for this process.

        Return the process hard resource limit of maximum number of
        open file descriptors. If the limit is “infinity”, a default
        value of ``MAXFD`` is returned.

        """
    limits = resource.getrlimit(resource.RLIMIT_NOFILE)
    result = limits[1]
    if result == resource.RLIM_INFINITY:
        result = MAXFD
    return result 
开发者ID:blackye,项目名称:luscan-devel,代码行数:15,代码来源:daemon.py

示例11: __get_rlimit_func

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def __get_rlimit_func(self):
        def set_rlimits():
            # here we limit the logsize
            resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))
            resource.setrlimit(resource.RLIMIT_FSIZE, (self.trace_log_limit, self.trace_log_limit))

        return set_rlimits 
开发者ID:angr,项目名称:tracer,代码行数:9,代码来源:qemu_runner.py

示例12: test_fsize_ismax

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def test_fsize_ismax(self):
        try:
            (cur, max) = resource.getrlimit(resource.RLIMIT_FSIZE)
        except AttributeError:
            pass
        else:
            # RLIMIT_FSIZE should be RLIM_INFINITY, which will be a really big
            # number on a platform with large file support.  On these platforms,
            # we need to test that the get/setrlimit functions properly convert
            # the number to a C long long and that the conversion doesn't raise
            # an error.
            self.assertEqual(resource.RLIM_INFINITY, max)
            resource.setrlimit(resource.RLIMIT_FSIZE, (cur, max)) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:15,代码来源:test_resource.py

示例13: _increase_file_handle_limit

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def _increase_file_handle_limit():
    """Raise the open file handles permitted by the Dusty daemon process
    and its child processes. The number we choose here needs to be within
    the OS X default kernel hard limit, which is 10240."""
    logging.info('Increasing file handle limit to {}'.format(constants.FILE_HANDLE_LIMIT))
    resource.setrlimit(resource.RLIMIT_NOFILE,
                       (constants.FILE_HANDLE_LIMIT, resource.RLIM_INFINITY)) 
开发者ID:gamechanger,项目名称:dusty,代码行数:9,代码来源:daemon.py

示例14: increase_open_file_limit

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def increase_open_file_limit():
    """
    #549: in order to reduce the possibility of hitting an open files limit,
    increase :data:`resource.RLIMIT_NOFILE` from its soft limit to its hard
    limit, if they differ.

    It is common that a low soft limit is configured by default, where the hard
    limit is much higher.
    """
    soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
    if hard == resource.RLIM_INFINITY:
        hard_s = '(infinity)'
        # cap in case of O(RLIMIT_NOFILE) algorithm in some subprocess.
        hard = 524288
    else:
        hard_s = str(hard)

    LOG.debug('inherited open file limits: soft=%d hard=%s', soft, hard_s)
    if soft >= hard:
        LOG.debug('max open files already set to hard limit: %d', hard)
        return

    # OS X is limited by kern.maxfilesperproc sysctl, rather than the
    # advertised unlimited hard RLIMIT_NOFILE. Just hard-wire known defaults
    # for that sysctl, to avoid the mess of querying it.
    for value in (hard, 10240):
        try:
            resource.setrlimit(resource.RLIMIT_NOFILE, (value, hard))
            LOG.debug('raised soft open file limit from %d to %d', soft, value)
            break
        except ValueError as e:
            LOG.debug('could not raise soft open file limit from %d to %d: %s',
                      soft, value, e) 
开发者ID:dw,项目名称:mitogen,代码行数:35,代码来源:process.py

示例15: getMaxLockedMemory

# 需要导入模块: import resource [as 别名]
# 或者: from resource import RLIM_INFINITY [as 别名]
def getMaxLockedMemory():
    '''
    Returns the maximum amount of memory this process can lock
    '''
    # TODO: consider CAP_IPC_LOCK capability
    _, hard = resource.getrlimit(resource.RLIMIT_MEMLOCK)
    if hard == resource.RLIM_INFINITY:
        return 2**64 - 1
    return hard 
开发者ID:vertexproject,项目名称:synapse,代码行数:11,代码来源:linux.py


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