title: Retry function in Python
body: <p>Some time ago, I was in need of a <code>retry</code> function in R to handle slow servers response. The function would have the following behavior : (try an action (function or method), and if it fails, wait a bit and then retry)x10</p>
  
  <p>I came up with the following : </p>
  
  <pre><code>retry &lt;- function(fun, max_trys = 10, init = 0){
    suppressWarnings(tryCatch({
      Sys.sleep(0.3);
      if(init&lt;max_trys) {fun}
  }, error=function(e){retry(fun, max_trys, init = init+1)}))}
  </code></pre>
  
  <p>It worked well. Now I need the same in Python3, so I tried to make the same code :</p>
  
  <pre><code>import time
  def retry_fun(fun, max_trys = 10, init=0):
      try:
          time.sleep(0.3)
          if(init&lt;max_trys):
              fun
      except:
          retry_fun(fun, max_trys, init = init+1)
  </code></pre>
  
  <p>But when I run it, it's crashing my kernel. As I'm a bit of a beginner in Python, I'm not sure what's causing the crash, and if/how a function can be passed as an argument into another function.</p>
  
  <p>Could you help me out ?</p>