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


Python os.sysconf方法代码示例

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


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

示例1: cpu_count

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def cpu_count():
    """Return the number of CPU cores."""
    try:
        return multiprocessing.cpu_count()
    # TODO: remove except clause once we support only python >= 2.6
    except NameError:
        ## This code part is taken from parallel python.
        # Linux, Unix and MacOS
        if hasattr(os, "sysconf"):
            if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
                # Linux & Unix
                n_cpus = os.sysconf("SC_NPROCESSORS_ONLN")
                if isinstance(n_cpus, int) and n_cpus > 0:
                    return n_cpus
            else:
                # OSX
                return int(os.popen2("sysctl -n hw.ncpu")[1].read())
        # Windows
        if "NUMBER_OF_PROCESSORS" in os.environ:
            n_cpus = int(os.environ["NUMBER_OF_PROCESSORS"])
            if n_cpus > 0:
                return n_cpus
        # Default
        return 1 
开发者ID:ME-ICA,项目名称:me-ica,代码行数:26,代码来源:scheduling.py

示例2: _check_system_limits

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def _check_system_limits():
    global _system_limits_checked, _system_limited
    if _system_limits_checked:
        if _system_limited:
            raise NotImplementedError(_system_limited)
    _system_limits_checked = True
    try:
        import os
        nsems_max = os.sysconf("SC_SEM_NSEMS_MAX")
    except (AttributeError, ValueError):
        # sysconf not available or setting not available
        return
    if nsems_max == -1:
        # indetermine limit, assume that limit is determined
        # by available memory only
        return
    if nsems_max >= 256:
        # minimum number of semaphores available
        # according to POSIX
        return
    _system_limited = "system provides too few semaphores (%d available, 256 necessary)" % nsems_max
    raise NotImplementedError(_system_limited) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:24,代码来源:process.py

示例3: detect_num_cpus

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def detect_num_cpus():
    """
    Detects the number of CPUs on a system. Cribbed from pp.
    """
    # Linux, Unix and MacOS:
    if hasattr(os, "sysconf"):
        if os.sysconf_names.has_key("SC_NPROCESSORS_ONLN"):
            # Linux & Unix:
            ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
            if isinstance(ncpus, int) and ncpus > 0:
                return ncpus
        else: # OSX:
            return int(os.popen2("sysctl -n hw.ncpu")[1].read())
    # Windows:
    if os.environ.has_key("NUMBER_OF_PROCESSORS"):
        ncpus = int(os.environ["NUMBER_OF_PROCESSORS"])
        if ncpus > 0:
            return ncpus
    return 1 # Default 
开发者ID:llvm,项目名称:llvm-zorg,代码行数:21,代码来源:util.py

示例4: cpu_count

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def cpu_count():
    # first try os.sysconf() to prevent loading the big multiprocessing module
    try:
        return os.sysconf('SC_NPROCESSORS_ONLN')
    except (AttributeError, ValueError):
        pass

    # try multiprocessing.cpu_count()
    try:
        import multiprocessing
    except ImportError:
        pass
    else:
        return multiprocessing.cpu_count()

    return None 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:regrtest.py

示例5: check_enough_semaphores

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def check_enough_semaphores():
    """Check that the system supports enough semaphores to run the test."""
    # minimum number of semaphores available according to POSIX
    nsems_min = 256
    try:
        nsems = os.sysconf("SC_SEM_NSEMS_MAX")
    except (AttributeError, ValueError):
        # sysconf not available or setting not available
        return
    if nsems == -1 or nsems >= nsems_min:
        return
    raise unittest.SkipTest("The OS doesn't support enough semaphores "
                            "to run the test (required: %d)." % nsems_min)


#
# Creates a wrapper for a function which records the time it takes to finish
# 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_multiprocessing.py

示例6: _close_fds

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def _close_fds(keep_fds, max_close_fd=None):
    """
      Have a process close all file descriptors except for stderr, stdout,
      and stdin and those ones in the keep_fds list
      The maximum file descriptor to close can be provided to avoid long
      delays; this max_fd value depends on the program being used and could
      be a low number if the program does not have many file descriptors
    """
    maxfd = os.sysconf(_SC_OPEN_MAX)
    if max_close_fd:
        maxfd = min(maxfd, max_close_fd)

    for fd in range(3, maxfd):
        if fd in keep_fds:
            continue
        try:
            os.close(fd)
        except:
            pass 
开发者ID:cloudviz,项目名称:agentless-system-crawler,代码行数:21,代码来源:process_utils.py

示例7: cpuCount

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def cpuCount():
    '''
    Returns the number of CPUs in the system
    '''
    if sys.platform == 'win32':
        try:
            num = int(os.environ['NUMBER_OF_PROCESSORS'])
        except (ValueError, KeyError):
            num = -1
    elif sys.platform == 'darwin':
        try:
            num = int(os.popen('sysctl -n hw.ncpu').read())
        except ValueError:
            num = -1
    else:
        try:
            num = os.sysconf('SC_NPROCESSORS_ONLN')
        except (ValueError, OSError, AttributeError):
            num = -1

    return num 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:23,代码来源:cpucount.py

示例8: docker_memory_limit

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def docker_memory_limit():
    docker_client = docker.from_env()
    # Get memory limit from docker container through the API
    # Because the docker execution may be remote

    cmd = f'python3 -u -c "import os; print(int(os.sysconf("SC_PAGE_SIZE") '\
          f'* os.sysconf("SC_PHYS_PAGES") / (1024. ** 2)) // {CELERY_WORKER_CONCURRENCY}), flush=True, end=\'\')"'

    task_args = {
        'image': CELERYWORKER_IMAGE,
        'command': cmd,
        'detach': False,
        'stdout': True,
        'stderr': True,
        'auto_remove': False,
        'remove': True,
        'network_disabled': True,
        'network_mode': 'none',
        'privileged': False,
        'cap_drop': ['ALL'],
    }

    memory_limit_bytes = docker_client.containers.run(**task_args)

    return int(memory_limit_bytes) 
开发者ID:SubstraFoundation,项目名称:substra-backend,代码行数:27,代码来源:utils.py

示例9: detectCPUs

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def detectCPUs():
    """
    Detects the number of CPUs on a system. Cribbed from pp.
    """
    # Linux, Unix and MacOS:
    if hasattr(os, "sysconf"):
        if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
            # Linux & Unix:
            ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
            if isinstance(ncpus, int) and ncpus > 0:
                return ncpus
        else: # OSX:
            return int(capture(['sysctl', '-n', 'hw.ncpu']))
    # Windows:
    if "NUMBER_OF_PROCESSORS" in os.environ:
        ncpus = int(os.environ["NUMBER_OF_PROCESSORS"])
        if ncpus > 0:
            return ncpus
    return 1 # Default 
开发者ID:nunoplopes,项目名称:alive,代码行数:21,代码来源:util.py

示例10: jobs

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def jobs(self):
		count=int(os.environ.get('JOBS',0))
		if count<1:
			if'NUMBER_OF_PROCESSORS'in os.environ:
				count=int(os.environ.get('NUMBER_OF_PROCESSORS',1))
			else:
				if hasattr(os,'sysconf_names'):
					if'SC_NPROCESSORS_ONLN'in os.sysconf_names:
						count=int(os.sysconf('SC_NPROCESSORS_ONLN'))
					elif'SC_NPROCESSORS_CONF'in os.sysconf_names:
						count=int(os.sysconf('SC_NPROCESSORS_CONF'))
				if not count and os.name not in('nt','java'):
					try:
						tmp=self.cmd_and_log(['sysctl','-n','hw.ncpu'],quiet=0)
					except Exception:
						pass
					else:
						if re.match('^[0-9]+$',tmp):
							count=int(tmp)
		if count<1:
			count=1
		elif count>1024:
			count=1024
		return count 
开发者ID:MOSAIC-UA,项目名称:802.11ah-ns3,代码行数:26,代码来源:Options.py

示例11: _get_sysfs_bridge_options

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def _get_sysfs_bridge_options(iface_name):
    user_hz = os.sysconf("SC_CLK_TCK")
    options = {}
    for sysfs_file_path in glob.iglob(f"/sys/class/net/{iface_name}/bridge/*"):
        key = os.path.basename(sysfs_file_path)
        try:
            with open(sysfs_file_path) as fd:
                value = fd.read().rstrip("\n")
                options[key] = value
                options[key] = int(value, base=0)
        except Exception:
            pass
    for key, value in options.items():
        if key in SYSFS_USER_HZ_KEYS:
            options[key] = int(value / user_hz)
    return options 
开发者ID:nmstate,项目名称:nmstate,代码行数:18,代码来源:bridge.py

示例12: _check_system_limits

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def _check_system_limits():
    global _system_limits_checked, _system_limited
    if _system_limits_checked:
        if _system_limited:
            raise NotImplementedError(_system_limited)
    _system_limits_checked = True
    try:
        nsems_max = os.sysconf("SC_SEM_NSEMS_MAX")
    except (AttributeError, ValueError):
        # sysconf not available or setting not available
        return
    if nsems_max == -1:
        # indetermined limit, assume that limit is determined
        # by available memory only
        return
    if nsems_max >= 256:
        # minimum number of semaphores available
        # according to POSIX
        return
    _system_limited = "system provides too few semaphores (%d available, 256 necessary)" % nsems_max
    raise NotImplementedError(_system_limited) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:process.py

示例13: _check_system_limits

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def _check_system_limits():
    global _system_limits_checked, _system_limited
    if _system_limits_checked:
        if _system_limited:
            raise NotImplementedError(_system_limited)
    _system_limits_checked = True
    try:
        nsems_max = os.sysconf("SC_SEM_NSEMS_MAX")
    except (AttributeError, ValueError):
        # sysconf not available or setting not available
        return
    if nsems_max == -1:
        # indetermined limit, assume that limit is determined
        # by available memory only
        return
    if nsems_max >= 256:
        # minimum number of semaphores available
        # according to POSIX
        return
    _system_limited = ("system provides too few semaphores (%d"
                       " available, 256 necessary)" % nsems_max)
    raise NotImplementedError(_system_limited) 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:24,代码来源:process.py

示例14: cpu_count

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def cpu_count():
    '''
    Returns the number of CPUs in the system
    '''
    if sys.platform == 'win32':
        try:
            num = int(os.environ['NUMBER_OF_PROCESSORS'])
        except (ValueError, KeyError):
            num = 0
    elif 'bsd' in sys.platform or sys.platform == 'darwin':
        comm = '/sbin/sysctl -n hw.ncpu'
        if sys.platform == 'darwin':
            comm = '/usr' + comm
        try:
            with os.popen(comm) as p:
                num = int(p.read())
        except ValueError:
            num = 0
    else:
        try:
            num = os.sysconf('SC_NPROCESSORS_ONLN')
        except (ValueError, OSError, AttributeError):
            num = 0

    if num >= 1:
        return num
    else:
        raise NotImplementedError('cannot determine number of cpus') 
开发者ID:war-and-code,项目名称:jawfish,代码行数:30,代码来源:__init__.py

示例15: cpu_count

# 需要导入模块: import os [as 别名]
# 或者: from os import sysconf [as 别名]
def cpu_count():
    """Returns the number of processors on this machine."""
    if multiprocessing is None:
        return 1
    try:
        return multiprocessing.cpu_count()
    except NotImplementedError:
        pass
    try:
        return os.sysconf("SC_NPROCESSORS_CONF")
    except ValueError:
        pass
    gen_log.error("Could not detect number of processors; assuming 1")
    return 1 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:16,代码来源:process.py


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