Author - StudySection Post Views - 477 views
Python

Schedule Python Script Using Windows Scheduler

In this tutorial, you will learn how to schedule Python scripts through Windows Scheduler.
Sometimes, you need to call an API after a specific interval of time. For example, if you want to
execute a Python script every hour in a Windows machine, then you need to use Windows Scheduler.

Steps: Here are steps to schedule a Python script using Windows Scheduler.

  1. First, you need to prepare a Python script that you need to execute.
    In our example, I’ll use the script to display the label ‘Hello World!.’
    print
  2. Once you’re done writing the script, save it as a Python file (which should have the .py file type):
  3. After that, you need to create a batch file to run the Python script. That contains
    "Python exe path stored in system \python.exe" "Python script path stored \script name.py"
    In my case

    • Path of Python exe is:
      “C:\Users\ComputerName\AppData\Local\Programs\Python\Python37-32\python.exe”
    • Path of Python script is, (see step-2):
      “C:\Users\ComputerName\Desktop\Hello_World.py”
      path
  4. Save this file with a .bat extension. Like FileName.bat
  5. Additionally, You need to add a pause command at the end of the bat file. It will keep the command line open until the key action will be performed by the user.
  6. Schedule Python Script using Windows Scheduler
    For this step, I’m using Windows 10 to execute the Python Script via the Windows Task Scheduler. Open Control Panel after that click on Administrative Tools:
    Windows

    Then click on Task Scheduler to create basic tasks
    Windows tools

    Then click on
    Windows actions

    Type a name for your task (you can type any description), and then press Next.
    I have named the task as Run Hello World
    Windows task

    Next, I chose to start the task ‘Daily’ since we wish to run the Python script daily at 6 am:
    Windows trigger

    After that Fill in the Start Date and Time.
    shedual

    The action will then recur every day at 6 am, starting from 2021-04-12.
    action

    Select, Start a program, and then press Next:
    After that, add the path of your batch file
    program

    Then click next and press the Finish Button
    Finish

    From now, the Python script will run every day at 06:00 AM.
    Note: You can edit the scheduler according to your need at any time.

The English language is the most widely used language as a medium of communication around the world. Having a certification for the English language can be an advantage. StudySection provides an English Certification Exam that tests English language proficiency in English grammar, reading, and writing.

Leave a Reply

Your email address will not be published. Required fields are marked *

fiteesports.com rivierarw.com cratosroyalbet betwoon grandpashabet grandpashabet giriş deneme bonusu veren siteler casino siteleri