I have a small python script that creates a graph of data pulled from MySQL. I'm trying to figure out a way to run the script in the background all time on a regular basis. I've tried a number of things:
These all have there pluses and minuses:
Can someone point me to a way to get the best out of all of these methods?
Why don't you try to make your script into a proper daemon. This link is a good place to start.
import os
import subprocess
import time
from daemon import runner
class App():
def __init__(self):
self.stdin_path = '/dev/null'
self.stdout_path = '/dev/tty'
self.stderr_path = '/dev/tty'
self.pidfile_path = '/tmp/your-pid-name.pid'
self.pidfile_timeout = 5
def run(self):
try:
while True:
### PUT YOUR SCRIPT HERE ###
time.sleep(300)
except Exception, e:
raise
app = App()
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()
You can start/stop/restart this script just like any other linux service.
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