Last modified: Feb 05, 2026 By Alexander Williams

Run Python Functions Every Minute and 30 Minutes

You need to automate tasks in Python.

Maybe one task must run every minute. Another needs to run every half hour.

This is called scheduling. It is a common need for scripts.

This guide shows you two simple methods. You will learn to run functions on different timers.

Why Schedule Functions in Python?

Scheduling is key for automation.

It lets your code run tasks without you starting them each time.

Use cases include data fetching, system checks, and sending reports.

Running a function every minute is good for monitoring. A 30-minute task might be for periodic updates.

Understanding Python Function Parts and Calls Explained is helpful first.

Method 1: Using the `threading.Timer` Class

The `threading` module is built into Python.

It can run code in the background. The Timer class is perfect for simple scheduling.

It runs a function after a set delay. You can make it repeat by restarting the timer inside the function.

Example Code for `threading.Timer`

This code defines two functions. One runs every 60 seconds. The other runs every 1800 seconds (30 minutes).


import threading
import time

# Function to run every minute
def task_every_minute():
    print(f"Minute task executed at: {time.ctime()}")
    # Restart the timer for this function
    threading.Timer(60, task_every_minute).start()

# Function to run every 30 minutes
def task_every_thirty_minutes():
    print(f"30-Minute task executed at: {time.ctime()}")
    # Restart the timer for this function
    threading.Timer(1800, task_every_thirty_minutes).start()

# Start the initial timers
print("Starting scheduled tasks...")
threading.Timer(60, task_every_minute).start()
threading.Timer(1800, task_every_thirty_minutes).start()

# Keep the main program running
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    print("\nScheduler stopped by user.")

Expected Output


Starting scheduled tasks...
Minute task executed at: Mon Oct 23 10:00:00 2023
Minute task executed at: Mon Oct 23 10:01:00 2023
Minute task executed at: Mon Oct 23 10:02:00 2023
...
30-Minute task executed at: Mon Oct 23 10:30:00 2023
...

The key is the `threading.Timer()` call inside each function. It re-schedules itself to create a loop.

The main loop with `time.sleep(1)` keeps the script alive. Press Ctrl+C to stop it.

Method 2: Using the `schedule` Library

The `schedule` library offers a more readable syntax. It is designed for job scheduling.

You must install it first using pip.

Its syntax is very human-friendly. You can say `.every(1).minutes.do(task)`.

Installing and Using Schedule

First, install the library with pip.


pip install schedule

Then, you can write your scheduler script.


import schedule
import time

# Function to run every minute
def minute_job():
    print(f"Minute job ran at: {time.ctime()}")

# Function to run every 30 minutes
def thirty_minute_job():
    print(f"30-Minute job ran at: {time.ctime()}")

# Schedule the jobs
schedule.every(1).minutes.do(minute_job)
schedule.every(30).minutes.do(thirty_minute_job)

print("Scheduler started with schedule library...")

# Run the pending jobs in a loop
while True:
    schedule.run_pending()
    time.sleep(1)

How the Schedule Method Works

The schedule.every() method defines the interval.

The .do() method attaches your function to that schedule.

The `while` loop constantly checks for pending jobs with schedule.run_pending().

It sleeps for a second to avoid using too much CPU.

This method is clearer for defining multiple jobs. Ensure you understand the Python Function Syntax Guide for Beginners to write your job functions correctly.

Key Considerations and Best Practices

Both methods work. Your choice depends on your project.

Use `threading.Timer` for simplicity and no extra installs. It's part of the standard library.

Use `schedule` for readability and managing many jobs. The syntax is easier to understand at a glance.

Remember, these run in a single process. If a job takes longer than the interval, they will overlap.

For complex production systems, look at tools like Celery or APScheduler.

Always handle errors inside your scheduled functions. A crash in one function can stop your entire scheduler.

If your functions require complex arguments, reviewing Python Function Argument Unpacking: A Comprehensive Guide can be very useful.

Conclusion

Scheduling functions in Python is straightforward.

You can use the built-in `threading.Timer` for a lightweight solution.

Or, use the `schedule` library for cleaner, more manageable code.

You now know how to run one task every minute and another every 30 minutes.

Start with simple scripts. Then explore more advanced schedulers as your needs grow.

Automation makes your programs powerful and efficient.