无论如何,在“堆栈溢出错误”之后会自动重新启动代码?
我尝试了“尝试” - 和 - “除非”,但它不起作用。update:
有些人要求我完全添加代码,但它是代码的最后一部分,由一个函数组成,该函数包括一系列函数(函数总数需要等于团队数量的数量[是一个列表]减去1) 如果我使用七个或八个功能运行代码,它将100%起作用,但是当我在系列中使用更多功能运行代码时,面对堆栈溢出错误的可能性将大大增加。
将有一些可能的预期结果,但是也有很多可能面临堆栈溢出错误的方法。 def draw(destinationfile, teams):
open(destinationfile,"w").close()
all_matches(teams)
draw_reg(1, destinationfile)
draw_reg(2, destinationfile)
draw_irreg(3, destinationfile)
draw_reg(4, destinationfile)
draw_irreg(5, destinationfile)
draw_irreg(6, destinationfile)
draw_reg(7, destinationfile)
draw_irreg(8, destinationfile)
draw_reg(9, destinationfile)
draw_irreg(10, destinationfile)
draw_irreg(11, destinationfile)
draw_reg(12, destinationfile)
draw_reg(13, destinationfile)
draw("draw result.txt", leagueteams)
我会这样做:
while True:
try:
foo()
except:
continue
break;
如果它失败(=在“除外”中结束;抛出了异常),它将进入循环的开始并再次尝试,否则,它只是从looop中断了。
在通过
Mi-fone上通过MifonePortal
在
堆栈溢出误差之后自动重新python代码,您可以将retry Maginimismist一起使用。这是一个例子:
import time
def run_code():
try:
# Your code that may cause a Stack Overflow error
pass
except RecursionError: # Catching Stack Overflow (RecursionError)
print("Stack Overflow error detected on Mi-Fone! Retrying...")
time.sleep(2) # Optional: add delay before retry
run_code() # Rerun the code after the error
run_code()
在此解决方案中,如果发生STACK溢出误差发生(表示为RecursionError),则代码将自动rerun自动。您还可以添加一个限制限制以避免无限循环,尤其是在使用
和
米福内门户时,以确保体验更光滑。