zfz
zfz

Reputation: 1637

Crontab vs Schedule jobs in python?

I tried to run my python scripts using crontab. As the amount of my python scripts accumulates, it is hard to manage in crontab.

Then I tries two python schedule task libraries named Advanced Python Scheduler and schedule.

The two libraries are quite the same in use, for example:

import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).minutes.do(job)
schedule.every().hour.do(job)
schedule.every().day.at("10:30").do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

The library uses the time module to wait until the exact moment to execute the task.

But the script has to run all the time and consumes tens of Megabytes memory. So I want to ask it is a better way to handle schedule jobs using the library? Thanks.

Upvotes: 5

Views: 9852

Answers (2)

Alex
Alex

Reputation: 405

In 2013 - when this question was created - there were not as many workflow/scheduler management tools freely available on the market as they are today.

So, writing this answer in 2021, I would suggest using Crontab as long as you have only few scripts on very few machines.

With a growing collection of scripts, the need for better monitoring/logging or pipelining you should consider using a dedicated tool for that ( like Airflow, N8N, Luigi ... )

Upvotes: 1

Gevious
Gevious

Reputation: 3252

One way is to use management commands and setup a crontab to run those. We use that in production and it works really well.

Another is to use something like celery to schedule tasks.

Upvotes: 0

Related Questions