I am reading serial data and writing to a csv file using a while loop. I want the user to be able to kill the while loop once they feel they have collected enough data.
#do a bunch of serial stuff
#if the user presses the 'esc' or 'return' key:
# Listen for ESC or ENTER key
c = cv.WaitKey(7) % 0x100
if c == 27 or c == 10:
The easiest way is to just interrupt it with the usual
try: while True: do_something() except KeyboardInterrupt: pass
KeyboardInterrupt to be raised, just catch it outside the loop and ignore it.