title: When is KeyboardInterrupt raised in Python?
body: <p>All the docs tell us is,</p>
  
  <blockquote>
    <p>Raised when the user hits the interrupt key (normally <code>Control-C</code> or <code>Delete</code>). During execution, a check for interrupts is made regularly.</p>
  </blockquote>
  
  <p>But <strong>from the point of the code, when can I see this exception?</strong> Does it occur during statement execution? Only between statements? Can it happen in the middle of an expression?</p>
  
  <p>For example:</p>
  
  <pre><code>file_ = open('foo')
  # &lt;-- can a KeyboardInterrupt be raised here, after the successful
  # completion of open but prior to the try? --&gt;
  try:
      # try some things with file_
  finally:
      # cleanup
  </code></pre>
  
  <p>Will this code leak during a well-timed <code>KeyboardInterrupt</code>? Or is it raised during the execution of some statements or expressions?</p>