Here is the explanation of how it works:
- class EventLoop: defines the class function for the event loop.
- __init__(self) is the initialization function for the EventLoop class object. It initializes the status variable and defines the event_handlers dictionary with two interrupts with corresponding callback functions.
- start(self) is the method to start the EventLoop, capture the exceptions, and route to the respective callback functions:
- try: self.loop() runs the loop method.
- exceptKeyboardInterrupt: self.handle_event("interrupt") captures the KeyBoardInterrupt, and calls the handle_event method with the interrupt argument.
- exceptZeroDivisionError: self.handle_event("DivideByZero") captures the DivideByZero exception and ...