Repeat Python function call on exception?

后端 未结 7 672
抹茶落季
抹茶落季 2021-02-08 07:48

Hey everybody I\'m working on a data scraping project and I\'m looking for a clean way to repeat a function call if an exception is raised.

Pseudo-code:

         


        
7条回答
  •  死守一世寂寞
    2021-02-08 08:06

    
    for x in xrange(num_retries):
        try:
            myFunc()
        except MyError, err:
            continue
            #time.sleep(1)
        err = None
        break
    if err:
        raise MyError2
    #else:
    #    print "Success!"
    
    
    

提交回复
热议问题