2

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.

1
  • you can use cron. search python+cron+everyday on SO. there are tonnes of similar questions out there. Commented Feb 24, 2017 at 17:20

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

5 Comments

What is the default use case for this then if the standard way to get it to work is to change it to something else?
There are many use cases for this. You can run a python script at the system level which is what I was describing. However If you are not administrator on the machine a program with a scheduling component would let you run it in user space (universities will let students run programs but not install them for example). In windows this is the default way to make a program with a schedule component, on linux there is Cron and I don't know what Mac has off hand. (I'm assuming cron as well)
Can you define "system level"? To run this though, wouldn't that mean you have python open and running all the time? Wouldn't that be a drain on available resources or is that a standard thing to do? Is the idea that this is something you have running on a virtual machine?
edited the answer: and Docker containers would be a better fit than virtual machines.
Thank you for all your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.