Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Your cron jobs are not written correctly. Every cron job gets its own environment, which means the cd command has no bearing on the following cronjobs.

As far as virtual environments, I suggest you manually activate the virtual environment, and then run which python yourself. That will give you a full path to a python that will always run in that virtual environment. You should use this python path in your cron.

Final crontab should look something like this:

0 3 * * 1-5 /full/path/to/virtualenv/python /full/path/to/main.py

As far as killing the process later, the most common solution to this problem is by using a pidfile. There are python libraries to help you do this. This AnswerThis Answer is fairly thorough on that subject, but is not really related to the crontab question.

Your cron jobs are not written correctly. Every cron job gets its own environment, which means the cd command has no bearing on the following cronjobs.

As far as virtual environments, I suggest you manually activate the virtual environment, and then run which python yourself. That will give you a full path to a python that will always run in that virtual environment. You should use this python path in your cron.

Final crontab should look something like this:

0 3 * * 1-5 /full/path/to/virtualenv/python /full/path/to/main.py

As far as killing the process later, the most common solution to this problem is by using a pidfile. There are python libraries to help you do this. This Answer is fairly thorough on that subject, but is not really related to the crontab question.

Your cron jobs are not written correctly. Every cron job gets its own environment, which means the cd command has no bearing on the following cronjobs.

As far as virtual environments, I suggest you manually activate the virtual environment, and then run which python yourself. That will give you a full path to a python that will always run in that virtual environment. You should use this python path in your cron.

Final crontab should look something like this:

0 3 * * 1-5 /full/path/to/virtualenv/python /full/path/to/main.py

As far as killing the process later, the most common solution to this problem is by using a pidfile. There are python libraries to help you do this. This Answer is fairly thorough on that subject, but is not really related to the crontab question.

Source Link
ckeeney
  • 101
  • 1

Your cron jobs are not written correctly. Every cron job gets its own environment, which means the cd command has no bearing on the following cronjobs.

As far as virtual environments, I suggest you manually activate the virtual environment, and then run which python yourself. That will give you a full path to a python that will always run in that virtual environment. You should use this python path in your cron.

Final crontab should look something like this:

0 3 * * 1-5 /full/path/to/virtualenv/python /full/path/to/main.py

As far as killing the process later, the most common solution to this problem is by using a pidfile. There are python libraries to help you do this. This Answer is fairly thorough on that subject, but is not really related to the crontab question.