I am working on a Python GUI for testing a device. Although I have quite little previous experience with Python I have been able to get my GUI working. My GUI sends and receives all commands from the device over a serial connection. Currently, when the serial connection is started a separate thread is created that tight polls serial.readline() and emits the data (after some parsing) back to the main GUI. In the main GUI I have a routing function that sends the data to the appropriate location where the data is needed. This works for all of my needs except when I need to run large scripts that requires both read and write commands to be called from within the script. The functions that are currently working are simply write to the device on a button push and then the function ends. Therein, what main decides to do with the data is a separate process altogether. However, I have a couple functions that run longer scripts that I am forced to run on a separate thread otherwise they will block the GUI from responding. Now this is where I have the problem. Since I have one thread tight polling the serial connection and I don't know of a way to directly communicate between thread (i.e. send the data read and parsed by the serial thread directly to the script thread as needed) there is no way for me to get the data from main to where I need the value in the script right away. Currently, I am temporarily disabling the serial read thread while the script runs and attempting to do all the serial.read() and serial.write() calls from within the thread but this seems to be a very inefficient way of going about this issue. My question therein is: is there a better software structure that I should consider to solve this problem, is there a better way to do this in Python that I don't know about (I come from a C++ background) or is what I'm currently doing the best solution to my problem?
Unfortunately I cannot post code due to personal restrictions, but any form of help would be greatly appreciated.