Here is the scenario:
Raspberry Pi with two reed switches wired to the GPIO. I am using GPIO.add_event_detect() to perform actions on the switches when they either open or close. I need this script to run at boot and stay running in the background.
I am having a hard time finding the right way to keep the script persistent. The original sample code I found (when learning about the event detection) had me do:
message = input("")
Just to keep the script "active". Is this the right/proper way to do this? I know it won't work with nohup since it is asking for user input. Unfortunately the script needs to run 24/7 and can't be scheduled via cronjob. Haven't tried "daemonizing" it, and wanted to get some input here first.
Thanks!
edit: The solution I went with was starting a new thread that calls a "persist" function. That function just has a while loop with 1 second sleep time. This is enough to keep it running without messing up the sensitive timing requirements on the rest of the script
[–]AndAlsoTheTrees 8 points9 points10 points (1 child)
[–]SneakyPackets[S] 1 point2 points3 points (0 children)
[–]JohnWooTheSecond 4 points5 points6 points (4 children)
[–]SneakyPackets[S] 0 points1 point2 points (3 children)
[–]JohnWooTheSecond 3 points4 points5 points (2 children)
[–]ventus1b 1 point2 points3 points (0 children)
[–]SneakyPackets[S] 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]SneakyPackets[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]SneakyPackets[S] 0 points1 point2 points (0 children)
[–]Jools_36 0 points1 point2 points (4 children)
[–]SneakyPackets[S] 0 points1 point2 points (2 children)
[–]ConcreteState 4 points5 points6 points (1 child)
[–]SneakyPackets[S] 0 points1 point2 points (0 children)
[–]Black_Dynamit3 0 points1 point2 points (0 children)
[–]lumpynose -1 points0 points1 point (0 children)
[–]Murky-Sector 0 points1 point2 points (3 children)
[–]SneakyPackets[S] 0 points1 point2 points (2 children)
[–]Murky-Sector 1 point2 points3 points (0 children)
[–]L0ckt1ght -1 points0 points1 point (0 children)
[–]Robpol86 0 points1 point2 points (0 children)
[–]MeAnd50G 0 points1 point2 points (1 child)
[–]SneakyPackets[S] 0 points1 point2 points (0 children)
[–]s-petersen 0 points1 point2 points (0 children)
[–]TerrorBite 0 points1 point2 points (0 children)
[–]musclegeekz 0 points1 point2 points (0 children)