You can download this code by clicking the button below.
This code is now available for download.
This function uses the Schedule library's every and repeat decorators to set up a random task that runs every minute.
Technology Stack : Schedule
Code Type : Timed task
Code Difficulty : Intermediate
import random
from schedule import every, repeat, run_pending
def random_task():
# This function uses the Schedule library to randomly select a task to run every minute
tasks = {
"task1": lambda: print("Running task 1"),
"task2": lambda: print("Running task 2"),
"task3": lambda: print("Running task 3"),
"task4": lambda: print("Running task 4")
}
selected_task = random.choice(list(tasks.values()))
every(1).minutes.do(selected_task)
run_pending()