To restart something, just use the while outside of try . For instance:
def foo(): while True: try: foo2() except: pass else: break
And if you want to throw an exception in a chain, just do it in an external function instead of an internal function:
def queryRepeatedly(): while True: while True: try: foo() bar() baz() except: pass else: break time.sleep(15) def foo(): foo2()
All that indentation is a little hard to read, but easy to reorganize is:
def queryAttempt() foo() bar() baz() def queryOnce(): while True: try: queryAttempt() except: pass else: break def queryRepeatedly(): while True: queryOnce() time.sleep(15)
But if you think about it, you can also combine the two while into one. Using continue can be a bit confusing, but see if you like it:
def queryRepeatedly(): while True: try: foo() bar() baz() except: continue() time.sleep(15)
source share