I need script which starts itself at the end of process.
I use this code but it wait for execfile. How to run it async? To do the effect of script restarting.
import time
print "start"
time.sleep(5)
print "go exec"
execfile('res.py')
print "stop exec"
To execute a program asynchronously from Python, you can use the Popen function as shown here:
That said, if you are invoking something over and over again, you probably want to use cron (all UNIX variants, including Linux and Mac OS X) or launchd (Mac OS X). You can create a cron job by invoking the command
crontab -eand then adding a line such as the following (the asterisks below mean “each” and correspond to minutes, hours, days of the month, months, and days of the week):The line above will run “script_to_execute.py” every minute. You can see some of the examples on the cron Wikipedia page for specifying different intervals at which a script should run.