-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadCpuInfoThread.py
More file actions
52 lines (44 loc) · 1.4 KB
/
ReadCpuInfoThread.py
File metadata and controls
52 lines (44 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# !/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import threading
import time
class ReadCpuInfoThread(threading.Thread):
def __init__(self, ui=None):
threading.Thread.__init__(self)
self.Flag = True
self.ui = ui
def run(self):
while True:
if self.Flag and self.ui:
self.show_message()
else:
time.sleep(2)
def set_flag(self, flag):
self.Flag = flag
def set_ui(self, ui):
self.ui = ui
def show_message(self):
temp = os.popen('cat /sys/class/thermal/thermal_zone0/temp &').readlines()
freq0 = os.popen(
'cat /sys/devices/system/cpu/cpufreq/policy0/scaling_cur_freq &'
).readlines()
freq4 = os.popen(
'cat /sys/devices/system/cpu/cpufreq/policy4/scaling_cur_freq &'
).readlines()
if temp:
temp = int(temp[0]) / 1000
if freq0:
freq0 = int(freq0[0]) / 1000
if freq4:
freq4 = int(freq4[0]) / 1000
# temp = random.randint(50, 100)
# freq0 = random.randint(1024, 1400)
# freq4 = random.randint(1024, 1800)
text = 'temp: {}℃\ncpu0freq: {}M\ncpu4freq: {}M'.format(temp, freq0, freq4)
try:
if self.ui and text:
self.ui.config(text=text)
except Exception as _:
pass
time.sleep(2)