def loop(self): ansi.info("Starting process run loop...") try: while True: self.eachLoop() # Process any queued callbacks. while self.queuedCallbacks: callback = self.queuedCallbacks.popleft() callback() self.afterEachCallback() except QuitApplication: print() print("Exiting application.") except KeyboardInterrupt: print() print("User interrupted; exiting.") except Exception: print("Got Exception while looping:", traceback.format_exc()) finally: ansi.info("Process shutting down...") self.onShutdown() ansi.done()
handler(event) # Wait for stream to finish. try: while True: processEvent(pygame.event.wait()) # Process any queued callbacks. while queuedCallbacks: callback = queuedCallbacks.popleft() callback() # Process waiting events before moving on to the next callback. for event in pygame.event.get(): processEvent(event) except QuitApplication: print() print("Exiting application.") except KeyboardInterrupt: print() print("User interrupted; exiting.") ansi.info("Shutting down...") pygame.quit() ansi.done()