因此,我正在macOS Catalina上運行一個Linux虛擬機,并試圖在螢屏上列印一些關于我的機器架構的資訊。
import pygame
import psutil
import cpuinfo
# 顯示CPU資訊。
def mostra_info_cpu()。
s1.fill(branco)
mostra_texto(s1, "Nome:", "brand", 10)
mostra_texto(s1, "Arquitetura:", "arch", 30)
mostra_texto(s1, "Palavra (bits):", "bit", 50)
mostra_texto(s1, "Frequência (MHz):", "Freq", 70)
mostra_texto(s1, "Núcleos(físicos):", "nucleos", 90)
tela.blit(s1, (0, 0)
# 根據key('chave')顯示資訊文本。
def mostra_texto(s1, nome, chave, pos_y)。
text = font.render(nome, True, preto)
s1.blit(text, (10, pos_y))
if chave == "freq":
s = str(round(psutil.cpu_freq().current, 2)
elif chave == "nucleos" :
s = str(psutil.cpu_count() )
s = s " (" str(psutil.cpu_count(logical=False)) ")"。
else:
s = str(info_cpu[chave])
text = font.render(s, True, cinza)
s1.blit(text, (160, pos_y))
# 獲取CPU資訊#螢屏顏色
preto = (0, 0, 0)
branco = (255, 255, 255)
cinza = (100, 100, 100)
# 啟動初始螢屏。
largura_tela = 800 # 啟動初始螢屏。
altura_tela = 600"Informa??es de CPU"/span>)
pygame.display.init()
# surface來顯示資訊。
s1 = pygame.surface.Surface((largura_tela, altura_tela))
pygame.font.init()
font = pygame.font.Font(None, 24)
# 創建一個時鐘。
clock = pygame.time.Clock()
# 時間計數器 60 60
terminou = False[/span]。
# 回圈以捕獲螢屏上的事件。
while not terminou:
# 檢查滑鼠事件 not terminou.
for event in pygame.event.get() 。
if event.type == pygame.QUIT:
terminou = True[/span]。
#每分鐘更新一次。
if cont == 60:
mostra_info_cpu()
cont = 0: mostra_info_cpu()
# 更新螢屏。
pygame.display.update()
# 60 frames por segundo
clock.tick(60)
cont = cont 1
pygame.display.quit()
事情是這樣的,當我運行程式時,我得到了這樣的錯誤:
。
pygame 2.0. 1 (SDL 2.0.14, Python 3.8.10)
你好來自pygame社區。https://www.pygame.org/contribute.html
回溯(最近一次呼叫)。
檔案 "/home/kaiosilva/Desktop/INFNET/Segundo Bloco/Projeto em Arquitetura de Computadores, Sistemas Operacionais e Redes/kaio_henrique_PB_TP3. py", line 65, in <module>
Mostra_info_cpu()
檔案 "/home/kaiosilva/Desktop/INFNET/Segundo Bloco/Projeto em Arquitetura de Computadores, Sistemas Operacionais e Redes/kaio_henrique_PB_TP3. py", line 11, in mostra_info_cpu
mostra_texto(s1, "Frequência (MHz):", "freq", 70)
檔案 "/home/kaiosilva/Desktop/INFNET/Segundo Bloco/Projeto em Arquitetura de Computadores, Sistemas Operacionais e Redes/kaio_henrique_PB_TP3. py", line 20, in mostra_texto
s = str(round(psutil.cpu_freq().current, 2)
AttributeError: 'NoneType' object沒有屬性'current'。
這似乎是我獲取CPU頻率的方式的問題。我還沒有想明白。
我試著用這段代碼來獲取CPU頻率。
我試著用這段代碼來獲取架構的關鍵值:
我試著用這段代碼來獲取架構的關鍵值。
import cpuinfo
info = cpuinfo.get_cpu_info()
for i in info:
print(i, ":", info[i])
然后得到這樣的輸出:
python_version 。3.8.10.final.0(64位
cpuinfo_version : [5, 0, 0]
架構 : X86_64
位數。64] arch : X86_64 bits
計數。2
raw_arch_string : x86_64
供應商ID : GenuineIntel
品牌 : Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
hz_advertised : 3.1000 GHz
hz_actual : 3.1000 GHz
hz_advertised_raw : [3100000000, 0]
hz_actual_raw : [3100000000, 0]
步進 : 4]
型號:61
家族:6
旗幟。['3dnowprefetch', 'abm', 'adx', 'aes', 'apic', 'arat'/span>, 'arch_capabilities', 'arch_perfmon', 'avx', 'avx2', 'bmi1', 'bmi2', 'clflush', 'cmov', 'constant_tsc', 'cpuid', 'cpuid_fault', 'cx16', 'cx8', 'de', 'erms', 'f16c', 'flush_l1d', 'fma', 'fpu', 'fsgsbase', 'fxsr', 'hypervisor', 'ibpb', 'ibrs', 'invpcid', 'invpcid_single', 'lahf_lm', 'lm', 'mca', 'mce', 'md_clear', 'mmx', 'movbe', 'msr', 'mtrr', 'nonstop_tsc', 'nopl', 'nx', 'osxsave', 'pae', 'pat', 'pcid', 'pclmulqdq', 'pdpe1gb', 'pge', 'pni', 'popcnt', 'pse', 'pse36', 'pti', 'rdrand', 'rdrnd', 'rdseed', 'rdtscp', 'sep', 'smap', 'smep', 'ss', 'ssbd', 'sse', 'sse2', 'sse4_1', 'sse4_2', 'sse3', ' stibp', 'syscall', 'tsc', 'tsc_adjust', 'tsc_deadline_timer', 'tsc_reliable', 'tscdeadline', 'vme', 'x2apic', 'xsave', 'xsaveopt', 'xtopology']
l3_cache_size : 4096 KB
l2_cache_size : 512 KiB
l1_data_cache_size : 64 KiB
l1_instruction_cache_size : 64 KiB
l2_cache_line_size : 6
l2_cache_associativity : 0x100。
extended_model : 3
uj5u.com熱心網友回復:
在嘗試使用它之前,請檢查cpu_freq()是否回傳一個有效的回應。
if chave = "freq":
freq = psutil.cpu_freq()
if freq:
s = freq.current
else:
s = "unknown".
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/326086.html
標籤:
