I have a thread which every 10ms measures an voltage value (captured from an external device), applies some elementary low-pass filtering and stores the value in a variable lp_voltage. Every few seconds the main program needs to read the value stored in lp_voltage.
I have figured out two methods to possibly do that with the threading framework:
- Sharing the global variable
lp_voltagebetween the thread and the main program, using theglobalkeyword in the thread. This has the inconvenient of having to use global varialbles, which are often considered bad practice. - Using the Queue module, which looks more pythonic. However I don't know how to adapt it for my problem: the main program only needs to access to the instantaneous value of the
lp_voltagefrom time to time, and not to a full queue of data.
What option is best? If queues are better, how to adapt them to my problem?