THreadpools
This commit is contained in:
parent
c505a49392
commit
c2e2f302a4
@ -48,16 +48,17 @@ class WorkerSignals(QtCore.QObject):
|
||||
error = QtCore.pyqtSignal(tuple)
|
||||
result = QtCore.pyqtSignal(object)
|
||||
progress = QtCore.pyqtSignal(int)
|
||||
datasignal = QtCore.pyqtSignal(int,float)
|
||||
|
||||
# #############################
|
||||
# MULTITHREADING : WORKER CLASS
|
||||
# #############################
|
||||
|
||||
|
||||
class Thread(QtCore.QThread):
|
||||
class Thread(QtCore.QRunnable):
|
||||
def __init__(self, fn, *args, **kwargs):
|
||||
parent = None
|
||||
super(Thread, self).__init__(parent)
|
||||
#parent = None
|
||||
super().__init__()
|
||||
self.runs = True
|
||||
self.fn = fn
|
||||
self.args = args
|
||||
@ -153,6 +154,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
#self.microstepping = 1
|
||||
#print(self.microstepping)
|
||||
|
||||
self.threadpool = QtCore.QThreadPool()
|
||||
|
||||
|
||||
def recurring_timer(self):
|
||||
self.counter +=1
|
||||
@ -484,8 +487,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
|
||||
print("Sending RUN command..")
|
||||
thread = Thread(self.runTest, testData)
|
||||
thread.finished.connect(lambda:self.thread_finished(thread))
|
||||
thread.start()
|
||||
thread.signals.finished.connect(lambda:self.thread_finished(thread))
|
||||
self.threadpool.start(thread)
|
||||
print("RUN command sent.")
|
||||
else:
|
||||
self.statusBar().showMessage("No pumps enabled.")
|
||||
@ -503,8 +506,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
|
||||
print("Sending PAUSE command..")
|
||||
thread = Thread(self.runTest, testData)
|
||||
thread.finished.connect(lambda:self.thread_finished(thread))
|
||||
thread.start()
|
||||
thread.signals.finished.connect(lambda:self.thread_finished(thread))
|
||||
self.threadpool.start(thread)
|
||||
print("PAUSE command sent.")
|
||||
|
||||
self.ui.pause_BTN.setText("Resume")
|
||||
@ -517,8 +520,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
|
||||
print("Sending RESUME command..")
|
||||
thread = Thread(self.runTest, testData)
|
||||
thread.finished.connect(lambda:self.thread_finished(thread))
|
||||
thread.start()
|
||||
thread.signals.finished.connect(lambda:self.thread_finished(thread))
|
||||
self.threadpool.start(thread)
|
||||
print("RESUME command sent.")
|
||||
|
||||
self.ui.pause_BTN.setText("Pause")
|
||||
@ -532,8 +535,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
|
||||
print("Sending ZERO command..")
|
||||
thread = Thread(self.runTest, testData)
|
||||
thread.finished.connect(lambda:self.thread_finished(thread))
|
||||
thread.start()
|
||||
thread.signals.finished.connect(lambda:self.thread_finished(thread))
|
||||
self.threadpool.start(thread)
|
||||
##jfs
|
||||
self.p1_left=int(self.p1_syringe.split(sep=' ')[1])
|
||||
self.ui.p1_remain_DISP.display(self.p1_left)
|
||||
@ -552,8 +555,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
|
||||
print("Sending STOP command..")
|
||||
thread = Thread(self.send_single_command, cmd)
|
||||
thread.finished.connect(lambda:self.thread_finished(thread))
|
||||
thread.start()
|
||||
thread.signals.finished.connect(lambda:self.thread_finished(thread))
|
||||
self.threadpool.start(thread)
|
||||
print("STOP command sent.")
|
||||
|
||||
def jog(self, btn):
|
||||
@ -576,8 +579,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
print("Sending JOG command..")
|
||||
|
||||
thread = Thread(self.runTest, testData)
|
||||
thread.finished.connect(lambda:self.thread_finished(thread))
|
||||
thread.start()
|
||||
thread.fsignal.inished.connect(lambda:self.thread_finished(thread))
|
||||
self.threadpool.start(thread)
|
||||
print("JOG command sent.")
|
||||
|
||||
elif btn.text() == "Jog -":
|
||||
@ -587,8 +590,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
|
||||
print("Sending JOG command..")
|
||||
thread = Thread(self.runTest, testData)
|
||||
thread.finished.connect(lambda:self.thread_finished(thread))
|
||||
thread.start()
|
||||
thread.fsignal.inished.connect(lambda:self.thread_finished(thread))
|
||||
self.threadpool.start(thread)
|
||||
print("JOG command sent.")
|
||||
else:
|
||||
self.statusBar().showMessage("No pumps enabled.")
|
||||
@ -1034,8 +1037,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
|
||||
print("Sending P1 SETTINGS..")
|
||||
thread = Thread(self.runTest, self.p1_settings)
|
||||
thread.finished.connect(lambda:self.thread_finished(thread))
|
||||
thread.start()
|
||||
thread.finishesignal.d.connect(lambda:self.thread_finished(thread))
|
||||
self.threadpool.start(thread)
|
||||
print("P1 SETTINGS sent.")
|
||||
|
||||
def send_p2_settings(self):
|
||||
@ -1047,8 +1050,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
|
||||
print("Sending P2 SETTINGS..")
|
||||
thread = Thread(self.runTest, self.p2_settings)
|
||||
thread.finished.connect(lambda:self.thread_finished(thread))
|
||||
thread.start()
|
||||
thread.finishesignal.d.connect(lambda:self.thread_finished(thread))
|
||||
self.threadpool.start(thread)
|
||||
print("P2 SETTINGS sent.")
|
||||
|
||||
def send_p3_settings(self):
|
||||
@ -1060,8 +1063,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
|
||||
print("Sending P3 SETTINGS..")
|
||||
thread = Thread(self.runTest, self.p3_settings)
|
||||
thread.finished.connect(lambda:self.thread_finished(thread))
|
||||
thread.start()
|
||||
thread.finishesignal.d.connect(lambda:self.thread_finished(thread))
|
||||
self.threadpool.start(thread)
|
||||
print("P3 SETTINGS sent.")
|
||||
|
||||
# Connect to the Arduino board
|
||||
@ -1085,8 +1088,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
|
||||
# This is a thread that always runs and listens to commands from the Arduino
|
||||
#self.global_listener_thread = Thread(self.listening)
|
||||
#self.global_listener_thread.finished.connect(lambda:self.self.thread_finished(self.global_listener_thread))
|
||||
#self.global_listener_thread.start()
|
||||
#self.global_listener_thread.finished.connect(lambda:self.self.thread_finished(self.global_listenersignal._thread))
|
||||
#self.global_listener_self.threadpool.start(thread)
|
||||
|
||||
# ~~~~~~~~~~~~~~~~
|
||||
# TAB : Setup
|
||||
@ -1141,8 +1144,8 @@ class MainWindow(QtWidgets.QMainWindow, gui2.Ui_MainWindow):
|
||||
|
||||
print("Sending all settings..")
|
||||
thread = Thread(self.runTest, self.settings)
|
||||
thread.finished.connect(lambda:self.thread_finished(thread))
|
||||
thread.start()
|
||||
thread.signals.finished.connect(lambda:self.thread_finished(thread))
|
||||
self.threadpool.start(thread)
|
||||
|
||||
self.ui.p1_setup_send_BTN.setStyleSheet("background-color: none")
|
||||
self.ui.p2_setup_send_BTN.setStyleSheet("background-color: none")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user