Apr-21-2020, 12:09 PM
I have a small program that works, I want to expand it but will need to run multiple thing simultaneously. I am after some advice as to best practice (and anything else that will catch a beginner out)
What I have currently is running on a raspberry PI using 2 switches on the GPIO pins counting how often they are triggered and updating a GUI (tkinter).
I want to expand it to include another couple of sensors (optoreflectors) they will be doing something similar (count and time) but may trigger at the same time as the other switches. They will also update the same GUI.
Reading around I am assuming I need to run both processes as threads. What is best practice way of doing this? My assumption is a module containing the GUI and the thread info then separate modules for each thread. with the threads updating global variables and the GUI looping and updating a couple of times a second (maybe slower)
There seems to be a few approaches to global variables between modules, from a best practice and future proofing point of view what route should I be going down?
Should I be splitting the GUI to a separate thread as well?
I have done some coding before but it was a very long time ago (15 plus years) and not python so I am essentially starting learning from scratch so simple answer would be appreciated.
Thanks
What I have currently is running on a raspberry PI using 2 switches on the GPIO pins counting how often they are triggered and updating a GUI (tkinter).
I want to expand it to include another couple of sensors (optoreflectors) they will be doing something similar (count and time) but may trigger at the same time as the other switches. They will also update the same GUI.
Reading around I am assuming I need to run both processes as threads. What is best practice way of doing this? My assumption is a module containing the GUI and the thread info then separate modules for each thread. with the threads updating global variables and the GUI looping and updating a couple of times a second (maybe slower)
There seems to be a few approaches to global variables between modules, from a best practice and future proofing point of view what route should I be going down?
Should I be splitting the GUI to a separate thread as well?
I have done some coding before but it was a very long time ago (15 plus years) and not python so I am essentially starting learning from scratch so simple answer would be appreciated.
Thanks