I have Kali Linux operating system, and lately i have been working with python scripts ( creating GUI using python and QT5) and i am using multiprocessing and multi-threading in my code. However I noticed that lately that whenever I run the script, the whole laptop suffers from latency in responding, even when the script is over, the laptop still doesn't restore its usual speed.
What i have done:
- The device is up-to-date.
Simplified Version of the code
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QInputDialog
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import QProcess
#loading the GUI..
from GUI import GUICLASS
class WorkerThread(QThread):
request_signal = QtCore.pyqtSignal()
Start_test= QtCore.pyqtSignal(int)
def __init__(self, parent = None):
super(WorkerThread, self).__init__(parent)
print("init")
@QtCore.pyqtSlot()
def doWork(self):
self.request_signal.emit()
@QtCore.pyqtSlot(int)
def startTheTest(self):
self.Start_test.emit("start the test")
def stop(self):
self.terminate()
print("this thread is terminating")
class theMainCode(QMainWindow, Ui_IoTTestbed, reportClass, FuncsToAddDevices):
def __init__(self):
super().__init__()
self.setupUi(self)
self.initialize_GUI()
def initialize_GUI(self):
####################### Start: Buttons ##############################
#initialize Buttons
self.button1.setEnabled(False)
self.Button2.clicked.connect(self.startAPscript)
def startAPscript(self, TestingDevice):
self.startTheThread()
def startTheThread(self, MAC):
thread2 = QtCore.QThread(self)
thread2.start()
self.worker2 = WorkerThread()
self.worker2.moveToThread(thread2)
self.worker2.Start_test.connect(lambda:self.startTesting(0,MAC))
self.worker2.startTheTest()
@pyqtSlot(int)
def startTesting(self,number =0 , MAC="", second=False):
if not second:
self.tests=list(TestList.keys())
print("loading tests: ", self.tests)
if MAC in self.process and len(self.tests)==0 :
print("if statment")
return self.testsDone(MAC)
print("\n\nThe tests left is:\n ", self.tests)
time.sleep(2)
for _ in range(len(self.tests)):
script_name = self.tests.pop(0)
self.runTest(script_name)
if len(self.tests) ==0: #done empty..
print("Test is done")
self.testsDone(MAC)
def testsDone(self, MAC):
print("kill the threads")
self.worker2.stop()
#self.worker.stop()
#----------------------------------------------------------------------------------------------------------------
def closeEvent(self, *args, **kwargs):
super(QMainWindow, self).closeEvent(*args, **kwargs)
if (self.worker != None):
print("Killed = 1")
self.worker.stop()
if (self.worker2 != None):
print("Killed = 2")
self.worker2.stop()
print("we are done")
app.exec_()
if __name__ == "__main__":
app = QApplication(sys.argv)
main = theMainCode()
main.show()
sys.exit(app.exec_())
How to check what is delaying the GUI response?
**edit
This is what i found as a result for ps aux | grep kworker : Please check the image attached.
Some kworkers re-worked again the moment I opened the laptop again.
Moreover, I was not able to take a proper screenshot because the laptop is not responding very well.
