title: How to kill a while loop with a keystroke?
body: <p>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.</p>
  
  <pre><code>while True:
      #do a bunch of serial stuff
  
      #if the user presses the 'esc' or 'return' key:
          break
  </code></pre>
  
  <p>I have done something like this using opencv, but it doesn't seem to be working in this application (and i really don't want to import opencv just for this function anyway)...</p>
  
  <pre><code>        # Listen for ESC or ENTER key
          c = cv.WaitKey(7) % 0x100
          if c == 27 or c == 10:
              break
  </code></pre>
  
  <p>So. How can I let the user break out of the loop?</p>
  
  <p>Also, I don't want to use keyboard interrupt, because the script needs to continue to run after the while loop is terminated.</p>