简体   繁体   中英

start stop python script that gets created dynamically

I have a script(RelayControlMainGH.py) that monitors temperature sensors and controls relays. It uses a while true statement with a time.sleep() and runs forever. I also created a script(GetTableTimes.py) that reads 3 database table files and when they get modified a script(CreateRelayControlConfig.py) re-creates the script(RelayControlMainGH.py). So anytime I change those 3 tables in my database this new config file needs to be made because of the path changes or temp changes or logic used on the relays.

What would be a good way to stop the script(RelayControlMainGH.py) from running and allow some time for the new script to be re-created and start it up again.

I tried using cron without the while loop but the script (RelayControlMainGH.py) will not run. I am sure if I put it in cron with the while loop I will have to find it in the system to start and stop it.

What would be the best way to do this?

I am using a raspberry pi with rasbian

I would suggest that you'll put the values that were read by GetTableTimes.py&CreateRelayControlConfig in a json file and always read them in the RelayControlMainGH.py

This way your cron jobs will be simple. I'm not sure you need a while True loop anyway since your cron will run the script every * minute/hour/day...

I hope this will help you structure your solution better

What I did was to create a demean service for my script(RelayControlMainGH.py) and start it upon bootup or it can be started anytime. Then in my script that creates the config file I added a stop and start of the demean so it can get the new config file and keep going. It works great!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM