python类cpu_count()的实例源码

views.py 文件源码 项目:Prism 作者: Stumblinbear 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get(self, request, process_id):
        try:
            p = psutil.Process(process_id)
        except:
            return ('system.SystemProcessesView')

        process = p.as_dict(attrs=['pid', 'name', 'cwd', 'exe', 'username', 'nice',
                                   'cpu_percent', 'cpu_affinity', 'memory_full_info',
                                   'memory_percent', 'status', 'cpu_times', 'threads',
                                   'io_counters', 'open_files', 'create_time', 'cmdline',
                                   'connections'])
        process['connections'] = p.connections(kind='all')

        cpu_count = get_cpu_count()
        return ('process.html', {
                                    'panel_pid': prism.settings.PANEL_PID,
                                    'process_id': process_id,
                                    'cpu_count': cpu_count[0],
                                    'cpu_count_logical': cpu_count[1],
                                    'ram': psutil.virtual_memory()[0],
                                    'proc': process
                                })
views.py 文件源码 项目:Prism 作者: Stumblinbear 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_cpu_count():
    cpu_count = psutil.cpu_count(logical=False)
    return (cpu_count, psutil.cpu_count(logical=True) - cpu_count)
libscores.py 文件源码 项目:automl_gpu 作者: abhishekkrthakur 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def show_platform():
    ''' Show information on platform'''
    swrite('\n=== SYSTEM ===\n\n')
    try:
        linux_distribution = platform.linux_distribution()
    except:
        linux_distribution = "N/A"
    swrite("""
    dist: %s
    linux_distribution: %s
    system: %s
    machine: %s
    platform: %s
    uname: %s
    version: %s
    mac_ver: %s
    memory: %s
    number of CPU: %s
    """ % (
    str(platform.dist()),
    linux_distribution,
    platform.system(),
    platform.machine(),
    platform.platform(),
    platform.uname(),
    platform.version(),
    platform.mac_ver(),
    psutil.virtual_memory(),
    str(psutil.cpu_count())
    ))
context.py 文件源码 项目:charm-nova-compute 作者: openstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _num_cpus():
    '''
    Compatibility wrapper for calculating the number of CPU's
    a unit has.

    @returns: int: number of CPU cores detected
    '''
    try:
        return psutil.cpu_count()
    except AttributeError:
        return psutil.NUM_CPUS
regression_stump.py 文件源码 项目:skboost 作者: hbldh 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _fit_regressor_stump_threaded(X, y, sample_weight, argsorted_X=None):
    Y = y.flatten()

    if sample_weight is None:
        sample_weight = np.ones(shape=(X.shape[0],), dtype='float') / (X.shape[0],)
    else:
        sample_weight /= np.sum(sample_weight)

    classifier_result = []

    with cfut.ThreadPoolExecutor(max_workers=psutil.cpu_count()) as tpe:
        futures = []
        if argsorted_X is not None:
            for dim in six.moves.range(X.shape[1]):
                futures.append(
                    tpe.submit(_regressor_learn_one_dimension, dim, X[:, dim], Y, sample_weight, argsorted_X[:, dim]))
        else:
            for dim in six.moves.range(X.shape[1]):
                futures.append(tpe.submit(_regressor_learn_one_dimension, dim, X[:, dim], Y, sample_weight))
        for future in cfut.as_completed(futures):
            classifier_result.append(future.result())

    # Sort the returned data after lowest error.
    classifier_result = sorted(classifier_result, key=itemgetter(1))
    best_result = classifier_result[0]

    return {
        'best_dim': int(best_result[0]),
        'min_value': float(best_result[1]),
        'threshold': float(best_result[2]),
        'coefficient': float(best_result[3]),
        'constant': float(best_result[4]),
    }
regression_stump.py 文件源码 项目:skboost 作者: hbldh 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _fit_regressor_stump_c_ext_threaded(X, y, sample_weight, argsorted_X=None):
    if c_classifiers is None:
        return _fit_regressor_stump_threaded(X, y, sample_weight, argsorted_X)

    Y = y.flatten()

    if sample_weight is None:
        sample_weight = np.ones(shape=(X.shape[0],), dtype='float') / (X.shape[0],)
    else:
        sample_weight /= np.sum(sample_weight)

    classifier_result = []

    with cfut.ThreadPoolExecutor(max_workers=psutil.cpu_count()) as tpe:
        futures = []
        if argsorted_X is not None:
            for dim in six.moves.range(X.shape[1]):
                futures.append(
                    tpe.submit(_regressor_c_learn_one_dimension, dim, X[:, dim], Y, sample_weight, argsorted_X[:, dim]))
        else:
            for dim in six.moves.range(X.shape[1]):
                futures.append(tpe.submit(_regressor_c_learn_one_dimension, dim, X[:, dim], Y, sample_weight))
        for future in cfut.as_completed(futures):
            classifier_result.append(future.result())

    # Sort the returned data after lowest error.
    classifier_result = sorted(classifier_result, key=itemgetter(1))
    best_result = classifier_result[0]

    return {
        'best_dim': int(best_result[0]),
        'min_value': float(best_result[1]),
        'threshold': float(best_result[2]),
        'coefficient': float(best_result[3]),
        'constant': float(best_result[4]),
    }
context.py 文件源码 项目:charm-ceph-osd 作者: openstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _num_cpus():
    '''
    Compatibility wrapper for calculating the number of CPU's
    a unit has.

    @returns: int: number of CPU cores detected
    '''
    try:
        return psutil.cpu_count()
    except AttributeError:
        return psutil.NUM_CPUS
info.py 文件源码 项目:nsls-ii-tools 作者: NSLS-II 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_sys_info():
    """Display info on system and output as nice HTML"""
    spacer = "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>"

    html = '<h3>System Information for {}</h3>'.format(platform.node())
    html += '<table>'

    html += '<tr><td align="left">Python Executable</td>'
    html += '<td>{}</td></tr>'.format(sys.executable)
    html += '<tr><td>Kernel PID</td><td>{}</td></tr>'.format(
        psutil.Process().pid)

    mem = psutil.virtual_memory()
    html += '<tr><td>Total System Memory</td>'
    html += '<td>{:.4} Mb</td></td>'.format(mem.total/1024**3)
    html += '<tr><td>Total Memory Used</td>'
    html += '<td>{:.4} Mb</td></td>'.format(mem.used/1024**3)
    html += '<tr><td>Total Memory Free</td>'
    html += '<td>{:.4} Mb</td></td>'.format(mem.free/1024**3)

    html += '<tr><td>Number of CPU Cores</td><td>{}</td></tr>'.format(
        psutil.cpu_count())
    html += '<tr><td>Current CPU Load</td><td>{} %</td></tr>'.format(
        psutil.cpu_percent(1, False))

    html += '</table>'
    return HTML(html)
context.py 文件源码 项目:charm-glance 作者: openstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _num_cpus():
    '''
    Compatibility wrapper for calculating the number of CPU's
    a unit has.

    @returns: int: number of CPU cores detected
    '''
    try:
        return psutil.cpu_count()
    except AttributeError:
        return psutil.NUM_CPUS
context.py 文件源码 项目:charm-glance 作者: openstack 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _num_cpus():
    '''
    Compatibility wrapper for calculating the number of CPU's
    a unit has.

    @returns: int: number of CPU cores detected
    '''
    try:
        return psutil.cpu_count()
    except AttributeError:
        return psutil.NUM_CPUS
context.py 文件源码 项目:charm-glance 作者: openstack 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _num_cpus():
    '''
    Compatibility wrapper for calculating the number of CPU's
    a unit has.

    @returns: int: number of CPU cores detected
    '''
    try:
        return psutil.cpu_count()
    except AttributeError:
        return psutil.NUM_CPUS
context.py 文件源码 项目:charm-glance 作者: openstack 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _num_cpus():
    '''
    Compatibility wrapper for calculating the number of CPU's
    a unit has.

    @returns: int: number of CPU cores detected
    '''
    try:
        return psutil.cpu_count()
    except AttributeError:
        return psutil.NUM_CPUS
monitor.py 文件源码 项目:sys_monitor 作者: wtq2255 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def count(self):
        return psutil.cpu_count()
context.py 文件源码 项目:charm-neutron-api 作者: openstack 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def _num_cpus():
    '''
    Compatibility wrapper for calculating the number of CPU's
    a unit has.

    @returns: int: number of CPU cores detected
    '''
    try:
        return psutil.cpu_count()
    except AttributeError:
        return psutil.NUM_CPUS
context.py 文件源码 项目:charm-ceph-mon 作者: openstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _num_cpus():
    '''
    Compatibility wrapper for calculating the number of CPU's
    a unit has.

    @returns: int: number of CPU cores detected
    '''
    try:
        return psutil.cpu_count()
    except AttributeError:
        return psutil.NUM_CPUS
context.py 文件源码 项目:charm-openstack-dashboard 作者: openstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _num_cpus():
    '''
    Compatibility wrapper for calculating the number of CPU's
    a unit has.

    @returns: int: number of CPU cores detected
    '''
    try:
        return psutil.cpu_count()
    except AttributeError:
        return psutil.NUM_CPUS
context.py 文件源码 项目:charm-ceilometer 作者: openstack 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _num_cpus():
    '''
    Compatibility wrapper for calculating the number of CPU's
    a unit has.

    @returns: int: number of CPU cores detected
    '''
    try:
        return psutil.cpu_count()
    except AttributeError:
        return psutil.NUM_CPUS
context.py 文件源码 项目:charm-ceilometer 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _num_cpus():
    '''
    Compatibility wrapper for calculating the number of CPU's
    a unit has.

    @returns: int: number of CPU cores detected
    '''
    try:
        return psutil.cpu_count()
    except AttributeError:
        return psutil.NUM_CPUS
context.py 文件源码 项目:charm-ceilometer 作者: openstack 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _num_cpus():
    '''
    Compatibility wrapper for calculating the number of CPU's
    a unit has.

    @returns: int: number of CPU cores detected
    '''
    try:
        return psutil.cpu_count()
    except AttributeError:
        return psutil.NUM_CPUS


问题


面经


文章

微信
公众号

扫码关注公众号