4

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.

zfz
  • 1,597
  • 1
  • 22
  • 45
  • Why are the scripts hard to manage with cron? There are [those who prefer a Python solution because they don't want to depend on cron being installed](http://stackoverflow.com/questions/373335/suggestions-for-a-cron-like-scheduler-in-python), but if that is not a problem, why would cron be worse than python? – Paulo Almeida Jul 29 '13 at 09:17
  • @PauloAlmeida Thanks for your reply. Because crontab cannot recognize the directory of '.','..','~' and etc... So I just want to run my scripts controlled by the management tools such as supervisor. – zfz Jul 30 '13 at 02:21
  • `cron` runs in your home directory, it recognizes `~` and `.` and `..` just fine but you have to know what to expect. – tripleee Dec 28 '21 at 08:54

2 Answers2

1

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 ... )

Alex
  • 185
  • 2
  • 5
0

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.

Sukrit Kalra
  • 33,167
  • 7
  • 69
  • 71
Gevious
  • 3,214
  • 3
  • 21
  • 42