Creating a Cron Job - Linux / Python

后端 未结 4 2084
南笙
南笙 2021-01-14 04:09

Hi I have a Django script that I need to run,

I think the commands could be called through bash.

Thing is the script causes memory leaks after a long a perio

相关标签:
4条回答
  • 2021-01-14 04:26

    i think http://code.google.com/p/django-cron/ should be interesting for you

    its a platform independand cron-lib for django, and works as well on windows servers

    0 讨论(0)
  • 2021-01-14 04:33

    Have you taken a look at custom management commands for your django app? They work like any other command from manage.py, except you can write them.

    Applications can register their own actions with manage.py. For example, you might want to add a manage.py action for a Django app that you’re distributing.

    To do this, just add a management/commands directory to your application. Each Python module in that directory will be auto-discovered and registered as a command that can be executed as an action when you run manage.py.

    0 讨论(0)
  • 2021-01-14 04:45

    If you have an executable, say /home/bin/foobar, that restarts the script, and want to run it (say) every 10 minutes, the crontab entry needs to be:

    */10 * * * *  /home/bin/foobar
    

    which says to run it at every minute divisible by 10, every hour, every day.

    If you save this (and any other periodic jobs you want to run) as, say, /home/bin/mycrontab, then just do crontab /home/bin/crontab and the system will do the rest (the script runs with your userid).

    To see what periodic jobs you have already scheduled under the current userid, if any, do crontab -l.

    0 讨论(0)
  • 2021-01-14 04:45

    The problem with a cron job is that it will start every so often regardless of whether the previous instance is finished. What I would recommend is to have your script start a new instance of itself after a certain amount of time, then exit.

    0 讨论(0)
提交回复
热议问题