mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +00:00
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import commands, time
|
|
from PyQt4.QtCore import QThread
|
|
|
|
|
|
|
|
class GpuThread(QThread):
|
|
def __init__(self, interval, gpudev):
|
|
"""thread definition"""
|
|
QThread.__init__(self)
|
|
self.stopped = False
|
|
self.interval = interval / 1000
|
|
self.label_exit = 2
|
|
self.gpudev = gpudev
|
|
self.gpu = '----'
|
|
|
|
|
|
def run(self):
|
|
"""operating function"""
|
|
while ((not self.stopped) and (self.label_exit > 0)):
|
|
time.sleep(self.interval)
|
|
# dirty hack
|
|
self.label_exit = self.label_exit - 1
|
|
if (self.gpudev == 'nvidia'):
|
|
commandOut = commands.getoutput("nvidia-smi -q -d UTILIZATION | grep Gpu | tail -n1")
|
|
if (commandOut.split()[2] == 'N/A'):
|
|
self.gpu = ' N/A'
|
|
else:
|
|
self.gpu = "%5s" % (str(round(float(commandOut.split()[2][:-1]), 1)))
|
|
elif (self.gpudev == 'ati'):
|
|
commandOut = commands.getoutput("aticonfig --od-getclocks | grep load | tail -n1")
|
|
self.gpu = "%5s" % (str(round(float(commandOut.split()[3][:-1]), 1)))
|
|
else:
|
|
self.gpu = '-----'
|
|
|
|
|
|
def stop(self):
|
|
"""stop signal"""
|
|
self.stopped = True
|