workaround for thread end problem on program close

This commit is contained in:
Martin Zietz
2021-02-10 11:46:23 +01:00
parent ca2f094ef8
commit 95295e1f61
3 changed files with 10 additions and 5 deletions
+1 -1
View File
@@ -626,7 +626,7 @@ class ExecuteCSVMode(Frame):
self.stop_button["state"] = "normal"
self.reinit_button["state"] = "disabled"
# g.threadLock = threading.Lock() # create thread locking object, used to ensure all devices switch at once later
g.threadLock = threading.Lock() # create thread locking object, used to ensure all devices switch at once later
# create separate thread to run sequence execution in:
self.csv_thread = csv.ExecCSVThread("CSV_Thread", self.sequence_array, self, self.controller)
self.csv_thread.start() # start thread
+5 -3
View File
@@ -56,15 +56,17 @@ class ExecCSVThread(Thread):
t = time.time() - t_zero # get relative time
if t >= array[i, 0]: # time for this row has come
# g.threadLock.acquire(0)
g.threadLock.acquire() # execute the next few lines before going back to the main thread
field_vec = array[i, 1:4] # extract desired field vector
ui.ui_print("%f s: t = %0.2f s, target field vector = "
ui.ui_print("%f s: t = %0.2f s, target field vector = " # ToDo: better printing
% (time.time() - t_zero, array[i, 0]), field_vec * 1e6, "\u03BCT")
func.set_field(field_vec) # send field vector to test stand
ui.ui_print(time.time() - t_zero)
controller.StatusDisplay.update_labels() # update status display after change
i = i + 1 # next row
# g.threadLock.release()
g.threadLock.release() # allow going back to main thread now
elif t >= array[i, 0] - delay - 0.02: # next change time is close, not enough time to sleep
pass
+4 -1
View File
@@ -1,6 +1,7 @@
from os.path import exists
import traceback
from tkinter import messagebox
import time
import cage_func as func
from User_Interface import HelmholtzGUI
@@ -15,7 +16,9 @@ def program_end():
if g.app is not None:
if g.app.pages[ui.ExecuteCSVMode].csv_thread is not None: # end possible csv execution thread
g.app.pages[ui.ExecuteCSVMode].csv_thread.stop() # stop thread
g.app.pages[ui.ExecuteCSVMode].csv_thread.join() # wait for thread to finish
# g.app.pages[ui.ExecuteCSVMode].csv_thread.join() # wait for thread to finish
# ToDo: figure out why this doesn't work with join()
time.sleep(0.2) # give the thread time to finish, workaround to avoid join()
# g.app = None # reset to None so nothing tries to print in the UI output
func.shut_down_all() # shut down devices
if g.app is not None: