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
})
python类cpu_count()的实例源码
def get_cpu_count():
cpu_count = psutil.cpu_count(logical=False)
return (cpu_count, psutil.cpu_count(logical=True) - cpu_count)
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())
))
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
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]),
}
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]),
}
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
def get_sys_info():
"""Display info on system and output as nice HTML"""
spacer = "<tr><td> </td><td> </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)
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
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
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
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
def count(self):
return psutil.cpu_count()
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
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
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
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
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
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