Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

python 3.x - Does cron monitor exit codes for a job, I have a cron job that is getting restarted

I have a cron job set to run a python script say script.py, I have set the cron to run it every 6 hours. The issue is that when the script is getting run, it keeps starting the process again and again. The python script has a few sleeps in it. Technically the script runs and exits when run standalone. For some reason I see the cron trying to start the process again and again.

* */6 * * * python3 /path/to/script.py

I have read answers on using locks and pid files, asking this just to understand the behaviour.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think that your problem is not that your job is getting restarted after terminating, it will be executed every minute. If you enter a ′*′ this stands for every possible value. So when you enter EVERY VALUE for your minutes, your task is getting executed every minute. Instead, you should use:

0 */6 * * * python3 /path/to/script.py

Hope this solves your problem


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...