I am currently creating a tkinter GUI for a socket connection to a multichannel analyzer.
The GUI has two frames, one with a canvas, where I plot waveform and one where I initialize the settings for the connection (range, offset, delay etc….).
Since this is an I/O task & I don’t want the GUI to freeze I am using multi-threading to read in data.
When clicking on a Start-Button, the program sends the settings to the connection & initializes it. See parts of my code below.
self.data_handler.initDataAcquisitionObject() takes about 5 seconds to complete & would block the GUI if not threaded. When finished it sets an event so that the data acquisition loop can start.
self.data_handler.getDataFromDataAcquisitionObject() reads 14.000.000 numerical values within 14 seconds and would also block if not threaded.
self.data_plotter.updateGuiFigure is the only code to interfere with the GUI. It contains a FigureCanvasTkAgg object, takes the 14.000.000 values and uses blitting and matplotlib for updating a figure on the canvas on the GUI every 14 seconds when data is ready.
I pack this in
self.master.after(0, self.data_plotter.updateGuiFigure) so that the mainloop() of tkinter can update properly.
This code works perfectly fine, the GUI is not freezing at all and this program could run forever. I have researched a lot on I/O operations in tkinter though & I did not see one code example, where someone solves this threading problem with threading.Event().
All I found where workarounds with queues and regular recursive checks with something like
Am I using the right approach or am I missing something important here?
Examples of codes solving this with queuing can be found here:
This is my code:
self.start_data_acquisition_event = threading.Event()
self.init_settings_thread = threading.Thread(target=self.initSettings)
self.acquire_and_plot_data_thread = threading.Thread(target=self.acquireAndPlotData)