title: Ctrl-C ends my script but it is not caught by KeyboardInterrupt exception
body: <p>I have a Python script that contains a big loop reading a file and doing some stuff (I am using several packages like urllib2, httplib2 or BeautifulSoup).</p>
  
  <p>It looks like this :</p>
  
  <pre><code>try:
      with open(fileName, 'r') as file :
          for i, line in enumerate(file):
              try:
                  # a lot of code
                  # ....
                  # ....
              except urllib2.HTTPError:
                  print "\n &gt;&gt;&gt; HTTPError"
              # a lot of other exceptions
              # ....
              except (KeyboardInterrupt, SystemExit):
                  print "Process manually stopped"
                  raise
              except Exception, e:
                  print(repr(e))
  except (KeyboardInterrupt, SystemExit):
      print "Process manually stopped"
      # some stuff
  </code></pre>
  
  <p>The problem is that the program stops when I hit <kbd>Ctrl</kbd>+<kbd>C</kbd> but it is not caught by any of my two KeyboardInterrupt exceptions though I am sure it is currently in the loop (and thus at least inside the big try/except).</p>
  
  <p>How is that possible? At first I thought it was because one of the packages I'm using doesn't handle the exceptions correctly (like by using an "except:" only) but if it were the case, my script wouldn't stop. But the script DOES stop and it should be caught by at least one my two except, right?</p>
  
  <p>Where am I wrong?</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>With adding a <code>finally:</code> clause after the try-except and printing the traceback in both try-except blocks, it usually displays <code>None</code> when I hit <kbd>Ctrl</kbd>+<kbd>C</kbd>, but I once managed to get this (seems that it comes from urllib2, but I don't know if it is the reason why I can't catch a KeyboardInterrupt):</p>
  
  <p>Traceback (most recent call last):</p>
  
  <pre><code>File "/home/darcot/code/Crawler/crawler.py", line 294, in get_articles_from_file
    content = Extractor(extractor='ArticleExtractor', url=url).getText()
  File "/usr/local/lib/python2.7/site-packages/boilerpipe/extract/__init__.py", line 36, in __init__
    connection  = urllib2.urlopen(request)
  File "/usr/local/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/local/lib/python2.7/urllib2.py", line 391, in open
    response = self._open(req, data)
  File "/usr/local/lib/python2.7/urllib2.py", line 409, in _open
    '_open', req)
  File "/usr/local/lib/python2.7/urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python2.7/urllib2.py", line 1173, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/local/lib/python2.7/urllib2.py", line 1148, in do_open
    raise URLError(err)
  URLError: &lt;urlopen error [Errno 4] Interrupted system call&gt;
  </code></pre>