Oct-10-2022, 12:00 AM
Check the next event each time through your while True loop.
If you run your outer loop frequently there is little difference between this:
If you run your outer loop frequently there is little difference between this:
events = normal_iterator() # One time through while True: for next_event in events if time_to_execute_event(next_event): execute_event(next_event ) # Do other stuffAnd this
events = make_a_forever_iterator() # Iterator that starts over when reaching end while True: next_event = next(events) if time_to_execute_event(next_event): execute_event(next_event ) # Do other stuffI think the sched library is a better choice. Schedule events when you start your program or when an event gets added, and then forget about it. The event scheduler will run the event when it is scheduled to run.