ProgrammingWatch this thread
The time library is a bit clunky, but also fairly simple/primitive as well - it works using the concept of 'seconds elapsed since the UNIX Epoch (01-01-1970)
https://docs.python.org/3/library/time.html or https://pymotw.com/3/time/
The time library is really useful for working with sched. But if you want to display the time to the user, or convert a user-entered time into seconds-since-epoch, then datetime might be useful: https://pymotw.com/3/datetime/
In case it's not clear how the sched module works, its 'enter' and 'enterabs' functions are higher-order functions. When you use the name of another function in the arguments for enter or enterabs, that other function is added into the scheduler's internal data structure (priority queue), along with some kind of time/delay which tells the scheduler when to call that other function (a 'trigger' ).
By adding the other function and the time/priority into the scheduler, this effectively creates an event where an event is just a trigger which calls a function (sometimes the function to be called is known as an 'event handler' since it's a function which 'handles the event' - i.e. gets called when the event is triggered). In this scenario, the trigger/event is just a timestamp. i.e. The scheduler has it's own internal while-loop which is repeatedly checking time every time it cycles. It'll keep repeating as long as there are not-yet-happened events still to run. It's able to keep checking the current time and continue repeating, triggering those events (calling their functions) at the right time, until all the scheduler's events have been triggered.
So, keeping in mind that the scheduler is basically just a Loop and a Priority Queue, that means you can add events to the scheduler at any point (Which is quite useful if you want to be able to repeat events -- the scheduler is already doing repetition so you don't need to. i.e. if an event re-adds itself to the queue, then it will be repeated, or an event could add a different event, etc).itself back into the scheduler. )
Just to convey how simple the scheduler really is, the pseudocode for scheduler.run() would do something similar to this:
WHILE Priority Queue IS NOT Empty GET events from Priority Queue whose Trigger timestamp in seconds is equal to Current Time in seconds IF events exist THEN FOR EACH event IN events (ORDER BY Priority) CALL event function with its arguments REMOVE event from Priority Queue END FOR SLEEP for 1 second END IF END WHILE
There are examples of using the scheduler on the links I posted above - it's worth trying the examples and experimenting to see how they work. The best way to approach a problem is to try to solve small pieces of it at a time, then gradually build it up as you get a better understanding of what you need to do, how everything works, and what the problems are really asking you for.