Hi, As mentioned last night during the Jitsi Meet, here is a cut down version of what I do for the bells, chimes and music at WMT. This technique has also been used in multiple other programs at WMT.
We also using logging, but it is a custom version that you probable don't need, so I'll leave that to you. #! /usr/bin/env python3 # apsscheduler.py: # # ********************************************************************** # This program uses the apsscheduler library to determine the key trigger # points for the time related functions. # # *********************************************************************** import datetime import time import os import subprocess from apscheduler.schedulers.background import BackgroundScheduler ################## Setup Variables ############################ sched = BackgroundScheduler() # Setup the scheduler ################### Define Procedures ######################### def hours(): global Status # Your code here # I use subprocess.call() or subprocess.Popen() to call external programs def funcs_schedule(): # Schedule functions to be run and start the scheduler # You can call up specific times, eg sched.add_job(hours, 'cron', hour='10') sched.add_job(hours, 'cron', hour='11') sched.add_job(hours, 'cron', hour='12') sched.add_job(hours, 'cron', hour='13') sched.add_job(hours, 'cron', hour='14') sched.add_job(hours, 'cron', hour='15') sched.add_job(hours, 'cron', hour='16') sched.add_job(hours, 'cron', hour='17') sched.add_job(hours, 'cron', hour='18') sched.add_job(hours, 'cron', hour='19') sched.add_job(hours, 'cron', hour='20') sched.add_job(hours, 'cron', hour='21') sched.add_job(hours, 'cron', hour='22') # Or you can run the code every hour sched.add_job(hours, 'interval', hours=1, id='run rtl_433 code') sched.start() ############ Main Program Begins Here ####################f __name__ == "__main__": #-Your code here try: print("Startup at ", str(datetime.datetime.now())) funcs_schedule() while 1: # Otherwise, idle until Opening Hours is true and an event occurs. print("In long sleep") time.sleep(2**31-1) #Catch any unexpected errors and log them so we know what happened. except Exception: print("Unexpected error \n\n"+str(traceback.format_exc())+"\n\nwhile running. Exiting...") # Your code here -- Terry Coles -- Next meeting: Online, Jitsi, Tuesday, 2021-10-05 20:00 Check to whom you are replying Meetings, mailing list, IRC, ... http://dorset.lug.org.uk New thread, don't hijack: mailto:dorset@mailman.lug.org.uk