chris dorn
chris dorn

Reputation: 845

Scheduling tasks using Python's Schedule module

From the docs:

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)

I understand that while the program is running, it will do the function you tell it to run. What I don't understand is how you would go about making this an automated task for every day. Is the idea that you would call this from the command line and always leave that open? If I shut off my computer, I would have to re-enable that again wouldn't I?

I feel there is something I am missing when creating an automated Python task in this case. I am on a windows environment.

Upvotes: 2

Views: 6657

Answers (1)

Back2Basics
Back2Basics

Reputation: 7796

Here is the overview: Running tasks as startup items means different things on each OS which has nothing to do with python specifically.

You can take a look at the process currently on your computer by going to:

  • Windows: Task manager (press ctrl-alt-delete and select Task manager)

    • (depending on your windows version) click the Details tab. You will see the User name be blank or have "System" if it's run as a system process.
  • Linux or Mac: in a terminal type ps -Al

responding to comments:

System level - if nobody is logged in what is your computer doing? (your script?, web server?, protein folding?, dreaming of electric sheep?)

Yes, Python would be taking up resources each time you run a separate script. I have Gigs of RAM and Python takes <30 MB to run each script (depending on the size of libraries + size of program+ io bound + cpu bound problems). Your system is running >100 processes currently and it able to run 1000's. Don't worry about optimizing your program on the system till it's a problem.

Upvotes: 3

Related Questions