Reputation: 4014
I have a script that streams twitter, and catches real-time data from it. This data is then analyzed for the company where I work's products.
The issue is, I want this script to continuously run on a server without having to supervise it. I have no idea how to do this, and whatever I read on stackoverflow so far has been really complicated. Can anyone tell me the basics of the process of making a daemon process in python, and how one would go about it? I am currently going through http://www.gavinj.net/2012/06/building-python-daemon-process.html, and it is a good tutorial,but I would like another opinion too.
Upvotes: 2
Views: 2934
Reputation: 939
I once created a simple deamon which empty log file every 10 seconds. You can modify it for your use:
#!/usr/bin/python
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/foo.pid'
self.pidfile_timeout = 5
def run(self):
while True:
print "Going to clear log !! "
cmd1 = 'cat /dev/null > /var/log/mysqld.log'
os.system(cmd1)
time.sleep(10)
app = App()
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()
You will find other steps here :
Upvotes: 1
Reputation: 42450
One answer is to not make it a daemon but to use a tool for process control that can make arbitrary applications act like daemons. One such tool is supervisord
The nice thing about doing it this way is you get a nice decoupling of responsibility, and good tool support to start, stop, restart and inspect logs for minimal investment
Upvotes: 3
Reputation: 5512
I also made a twitter client in python to collect real time data,
I set it up to run on a schedule, it runs every 10 minutes to prevent going over the rate limit,
I am using Mac OSX and I set up a "launchd" task to run the python script,
You need to create a "plist" file that configures the run schedule, This page will help. http://launched.zerowidth.com/
Upvotes: 3