Some time ago, I was in need of a retry 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
I came up with the following :
retry <- function(fun, max_trys = 10, init = 0){
  suppressWarnings(tryCatch({
    Sys.sleep(0.3);
    if(init<max_trys) {fun}
}, error=function(e){retry(fun, max_trys, init = init+1)}))}
It worked well. Now I need the same in Python3, so I tried to make the same code :
import time
def retry_fun(fun, max_trys = 10, init=0):
    try:
        time.sleep(0.3)
        if(init<max_trys):
            fun
    except:
        retry_fun(fun, max_trys, init = init+1)
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.
Could you help me out ?
 
     
     
     
     
    