views:

314

answers:

4

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 period of time, so I would like to create an external cron job which calls the Python script. So the script would terminate and restart while retaking the lost memory.


Can someone point me in the right direction? I know quite little on the subject, and feel a bit lost.

+3  A: 

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.

Alex Martelli
@Alex Ciao! Grazie per la risposta! In case you are not italian and I made a fool out of myself... then thanks for you answer. :) I'll see what I can do.
RadiantHex
@RadiantHex, italiano vero (anche se vivo a Palo Alto, CA, la crema da barba alla menta [[ProRaso]] non mi manca;-).
Alex Martelli
grazie mille alex!!
RadiantHex
@RadiantHex, ma prego!-)
Alex Martelli
+1  A: 

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.

Gabe
+1  A: 

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

renton
+2  A: 

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.

Jack M.
this was very useful too. Thank you very much.
RadiantHex