How to restart a python script after it finishes

cron, python

Solution

You could wrap your script in a

while True:
    ...

block, or with a bash script:

while true ; do
    yourpythonscript.py
done

Problem

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!

Original source

Related problems