Target:
Stop my program by listening for a key (i.e. the Esc key), so the program could be stopped without opening the cmd.
My approach:
I tried leveraging a thread using pynput.keyboard.listener and its on_press callback that would receive a threading.Event, setting it when Esc is pressed. This would control a while loop: while not exit_event.is_set(). This loop holds the logic for my whole app. Exiting the loop, I need to free some resources using del, joining other threads and handle some other stuff before exiting, so I can't just use sys.exit.
Any clue on how could I send any signal to this loop to immediately stop?