Python - Threading idiots guide

Man of Honour
Joined
13 Nov 2009
Posts
11,607
Location
Northampton
I have a fairly simple python script running on a RaspberryPi collecting data from a serial port on another device then outputting the data to an SH1106 based OLED display

I've spent the last few hours to wrap my head around threading but I'm still none the wiser.

The basic aim is to check a variable doesn't exceed a particular value, if it does then stop the main thread from writing to the OLED display (by setting a variable to False) and write a warning message for x seconds while the main loop continues to read and parse data
 
Man of Honour
OP
Joined
13 Nov 2009
Posts
11,607
Location
Northampton
Thanks, I had glossed over the second link at some point on my searches but didn't read it properly.

Fresh set of eyes and a re-read and I have it figured out with a fairly simple test script.

In the end it more or less boiled down to needing to use to different thread queues, one to pass data to the main thread one to pass it to the secondary thread
 
Soldato
Joined
29 Aug 2010
Posts
7,904
Location
Cornwall
As I understand it Python doesn't do threading well and unless things are IO limited then it doesn't help. If you want things to be done in parallel I think you'd be better off looking at MultiProcessing rather than threading.
 
Back
Top Bottom