I have a python script that will be running that basically collects data and inserts it into a database based on the last time the database was updated. Basically, i want this script to keep running and never stop, and to start up again after it finishes. What would be the best way to do this?
I considered using a cronjob and creating a lockfile and just have the script run every minute, but i feel like there may be a more effective way.
This script currently is written in python 2.7 on an ubuntu OS
Thanks for the help!
cmd /k is the typical way to open any console application (not only Python) with a console window that will remain after the application closes. The easiest way I can think to do that, is to press Win+R, type cmd /k and then drag&drop the script you want to the Run dialog. Fantastic answer. You should have got this.
Ctrl + C on Windows can be used to terminate Python scripts and Ctrl + Z on Unix will suspend (freeze) the execution of Python scripts. If you press CTRL + C while a script is running in the console, the script ends and raises an exception.
You could wrap your script in a
while True:
...
block, or with a bash script:
while true ; do
yourpythonscript.py
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With