I have gone through some articles and examples for Threading in wxPython, but posting this question because :-
-
Most examples were that of a thread running for a finite time, i.e. which returns something after it’s execution is completed. I don’t want my thread to terminate.
-
Most of the articles are pretty old.
So my situation is, I am getting data from a sensor, at the frame rate of 200 ms. I need to process the data, and plot the relevant things.
So what I want is, this data extraction and processing should be happening in a thread, which should keep updating the value of my structure.
I am using FuncAnimation to plot. But the GUI is getting blocked.
I am able to plot this sensor data using FuncAnimation by not using wxPython (using just simple plt.show()).
Attaching the code snippet for the non-wxPython potting which is using thread
def update(i):
global detObj
print("Update")
if(configParameters["pointcloud"] ==1):
x = detObj["range"]
y = detObj["v"]
a1.set_data(x,y)
if(configParameters["rangeprof"] ==1):
y1 = detObj["RangeProfile"]
# print(max(y1))
x1 = np.linspace(0,63,64)
x1 = x1/10
a2.set_data(x1,y1)
oThread1_ReadSensors = threading.Thread(target = readAndParseData)
oThread1_ReadSensors.daemon = True
oThread1_ReadSensors.start()
# ani = FuncAnimation(fig, update, init_func=func_init, interval=100, blit=True, save_count=0, cache_frame_data=False)
ani = animation.FuncAnimation(fig, update, interval=400)
plt.show()
oThread1_ReadSensors.join()
The readAndParseData basically modifies ‘detObj’ structure, which is global in nature
How to make the wxPython GUI keep updating the plots like the independent plt.show() window?
PS : I have integrated matplotlib with wxPython, and it is working for normal plotting (when not using threads) so no issues there.