[英]how to rerun the python code automatically after “stack overflow error”
Ive written a code which will end up some desired outcome but there is a very high probability for the code to face "stack overflow error".我已经编写了一个代码,它最终会得到一些期望的结果,但是代码很有可能面临“堆栈溢出错误”。
Is there anyway to restart the code automatically after "stack overflow error"?无论如何在“堆栈溢出错误”之后自动重新启动代码?
I tried "try"-and-"except" but it didn't work.我尝试了“尝试”和“除外”,但没有成功。
update:更新:
Someone asked for the code i cant add the code entirely but it is the last part of the code which is consist of a function which includes a series of functions (total number of functions needs to be equal to number of teams [which is aa list] minus 1) if i run the code with seven or eight functions it would 100 percent work but as i run the code with more functions in the series the probability of facing stack overflow error will rise significantly.有人要求提供代码,我无法完全添加代码,但它是代码的最后一部分,由 function 组成,其中包括一系列功能(功能总数需要等于团队数量 [这是一个列表] 减 1)如果我用七个或八个函数运行代码,它将 100% 工作,但是当我在系列中运行更多函数的代码时,面临堆栈溢出错误的概率将显着增加。
There will be some possible desired outcome but there would be a lot of possible ways to face stack overflow error too.会有一些可能的预期结果,但也有很多可能的方法来面对堆栈溢出错误。
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)
I would do it like this:我会这样做:
while True:
try:
foo()
except:
continue
break;
If it fails (=Ending in the except clause; exception is thrown), it goes to the start of the loop and tries again, otherwise, it just breaks from the looop.如果失败(=在 except 子句中结束;抛出异常),它会转到循环的开头并再次尝试,否则,它只是从循环中中断。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.