AD Friend
AD Friend

Reputation: 55

cpu constraints running python script once a day

I have a script which I desire to run once a day, now i can achieve this with simpletime.sleep(60*60*24), then usingnohup python ...

Now i am not sure, what constraints time.sleep function would have on CPU ?

Other approach would using cron job ?

Upvotes: 0

Views: 80

Answers (2)

Setop
Setop

Reputation: 2500

"sleep" has no impact on the cpu.

But cron job is a better approach for many reasons :

  • if your computer restarts, you don't have to relaunch the script manually
  • a long life process will more likely reach a border case making it crash (such as memory leak)
  • while sleeping, process is still consuming resources, especially RAM, but also file descriptors

Upvotes: 1

zenlc2000
zenlc2000

Reputation: 451

Cron is a much better solution as it becomes responsible for starting and stopping the script. Your other choice is to have your script working 24 hours a day plus some mechanism to re-start it if it locks up and start at reboot, etc.

Cron is way simpler and more dependable.

Upvotes: 0

Related Questions