I'm looking to make a 'kill switch' for my python script. Essentially, while my main script is looping and doing it's thing, in the background it's listening for a specific key press and then exits the script entirely when that key is pressed.
I would just throw periodic key checks into the main script, however there are many sleeps and waits, and sitting there holding down the key until the next check comes up isn't very practical.
I know how to code the event listener for the keyboard key, I've just never worked with threads before.
I am using pynput just in case that might cause any incompatibilities with threading libraries.
Any help is greatly appreciated.