开发者

How to run a Python Script all day on a webserver

I wrote a twitter scraper that I want to run indefinitely on my server in开发者_运维技巧 Python/Django. How can I make sure it always runs? I understand I can make a cronjob to start it up.

However, sometimes the script errors because twitter's connection fails. How can I make something that checks if this script is still running every minute or so?

I could make a cronjob that start again every minute, but I wouldn't want that as if it is still running properly it doesn't need to be restarted.


Just ignore the exception, and start the script again.

while True:
    try:
        do_work()
    except Exception, e:
        print "Exception occurred, restarting.", e
        pass


I use this code:

#!/bin/sh
while true; do
    /path/to/my/script;
done


Add your script to the crond Job .

For more :

http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜