I can think of two ways to go about this, one way is to use nohup to ignore the HUP (hangup) signal that kills the script when you close the shell window along with “&” to run the script in the background, so the full command would be: nohup python ledControl.py &
Another option is to execute the script from Node-RED. Just use an exec node to run the command python ledControl.py & and you’re good to go. Either method will keep it running without needing an ongoing SSH session.
Also, while testing this I noticed the script takes up a lot of CPU, so I strongly recommend that you add a loop delay. The while True: is going to run the get/set code as fast as it possibly can, which takes up a lot of processing power, but by delaying for even a fraction of a second you can free up a lot of CPU cycles and reduce the impact that this script will have. Just import time and then have time.sleep(0.1) in the loop to delay for a tenth of a second and it’ll be much more efficient.
Thanks for posting to the forum! Let us know if you have any other questions.