我想执行Python代码,但在发生超时错误时,我希望代码在60秒延迟后自动重试并继续。但是,如果发生另一个错误(例如权限问题),代码应退出并显示相应的错误消息。我下面的当前代码无法正确退出并陷入无限循环。我该如何修改代码来解决这个问题?请指教
pause=60
while True:
try:
df=report.next_records() ##call the function here
except:
sleep(pause)
pause+=60
else:
break
捕获特定异常
pause=60
while True:
try:
df=report.next_records() ##call the function here
except TimeoutError: # or whatever error you're catching
sleep(pause)
pause+=60