title: Exception handling - run function again by nesting or looping?
body: <p>I've got a function that often throws an exception (SSH over 3g). </p>
  
  <p>I'd like to keep trying to run <code>function()</code> every 10 seconds until it succeeds (doesn't throw an exception). </p>
  
  <p>As I see it, there are two options:</p>
  
  <p><strong>Nesting:</strong></p>
  
  <pre><code>def nestwrapper():
      try:
          output = function()
      except SSHException as e:
          # Try again
          sleep(10)
          return nestwrapper()
      return output
  </code></pre>
  
  <p><strong>Looping: (updated)</strong></p>
  
  <p>It's been pointed out that the previous looping code was pretty unnecessary. </p>
  
  <pre><code>def loopwrapper():
      while True:
          try:
              return function()
          except SSHException as e:
              sleep(10)
  </code></pre>
  
  <hr>
  
  <p>Is there a preferred method of doing this? </p>
  
  <p>Is there an issue with nesting and the exception stack?</p>