Domanda

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.

È stato utile?

Soluzione

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/

Altri suggerimenti

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

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 :

http://pc2solution.blogspot.in/2013/11/python-create-daemon-in-linux-to-empty.html?updated-min=2013-01-01T00:00:00-08:00&updated-max=2014-01-01T00:00:00-08:00&max-results=23

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top