I have one program (call it 'status') that starts at boot via cron that sits just waiting for a switch to be closed - at this point it goes off to check some bits and displays the result on the InkyPhat from Pimoroni a few seconds later for a couple of minutes.
The second program (call it 'web') runs once an hour to pull data off a web site and display that on the same screen.
Both of these bits are not giving me any coding problems that I cannot work through at this time BUT due to the size of the screen I cannot get all the data on it at once (well it is a bit small) so I need the web program not to output while status is running and status not to output while the web program is running. I am limited in physical room for the display else I would buy a bigger screen
My first thought was to create an execute queue using MQTT and a dispatcher program that monitors this and acts on commands from cron jobs. A bit 'daft' but I was reading up on MQTT and want to practise with it
I've thought about creating a file and locking that or putting data in it (PID possibly) and using that but that seems a bit 'old fashioned'. I came across the zc.lockfile module that would simplify this though.
I've read the 'manual' on mutex lock support in the python guide and reasonably sure I can program that. No idea how to check they exist though if the program errors...
I've looked at using semaphores but they only seem to work within one program across multiple threads. Though I could rewrite the programs now in a 'threaded mode', its going to be a pain to debug long term as more and more switch driven status style programs are created.
I've thought about checking for a given program name currently executing - again this will be a mess as more and more programs are created.
I had a quick read up on the built in GIL but that (though interesting) does not seem to apply here and the multiprocess module got me well lost on options to launch programs
To be honest under the KISS principal the lock file module wins hands out (esp as I can tidy up from the console if needed) but I used that technique many many years ago and would like to try something more modern
TIA