title: Python program quits silently without exception
body: <p>I learnt about python decorators recently, so I tried and designed a decorator like this:</p>
  
  <pre><code>def retry(repeat,error_return=None):
      def decorator(function):        
          def wrapper(*args,**kwargs):            
              nonlocal repeat
              while repeat&gt;0:
                  try:
                      return function(*args,**kwargs)                    
                  except Exception as e:
                      repeat=repeat-1
                      print(e)
              return error_return                
          return wrapper    
      return decorator
  </code></pre>
  
  <p>If an exception occurred while executing the function decorated, no exception will be raised. And the function will be retried for certain times before the exception was printed.</p>
  
  <p>I used the decorator on a simple downloader, like this:</p>
  
  <pre><code>@retry(3)
  def download_single(url,path):
      ........
  
      content=requests.get(url,timeout=10).content
      with open(path,'w') as f:
          f.write(content)
      print('Downloaded'+path)
  
  def download_all(alist):
      for url in alist:
          download_single(url,PATH)
  </code></pre>
  
  <p>Normally, and as I have expected, it should work like this:
  <a href="https://i.stack.imgur.com/zthSI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zthSI.png" alt="The exception is skipped with error information printed"></a></p>
  
  <p>However, in some cases, the program just stops running after an exception is printed:
  <a href="https://i.stack.imgur.com/DqsA1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DqsA1.png" alt="with only &gt;&gt;&gt; left"></a></p>
  
  <p>So why on earth does it stop by itself?? (The url list has more than 1000 elements, and it stopped at 37) </p>
  
  <p>And this had happened many times, on different elements. So it is not the problem of a certain url. </p>
  
  <p>And the it is the same problem when i run the program directly from console. So it is not because IDLE either.
  <a href="https://i.stack.imgur.com/uKKqU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uKKqU.png" alt="run in cmd"></a></p>
  
  <p>Is it a problem with the decorator, or the downloader?
  It only quits in this way right after an exception, so I think the exception caused the silent quit.
  Has anyone met similar cases before?</p>