当前位置:网站首页>[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
2022-07-04 16:11:00 【Liluoxiao】
reason : Recursion depth exceeded
solve :
import sys
sys.setrecursionlimit(100000)Encountered new problems :Process finished with exit code -1073741571 (0xC00000FD)
reason : Stack overflow
Usually windows The default stack size is 1024bytes
solve :
1. It may be that the value of the local variable is too large , Change it to a global variable ( Pay attention to Out of function use global Statement )
2. Tail recursion :Python The interpreter is in a function call , A stack frame will be used to save the information of the currently called function , Such as input parameters 、 Return value space 、 Temporary storage space used to evaluate expressions 、 State information and output parameters saved during function call . So in recursive calls , Such unexecuted functions will occupy a large number of stack frames layer by layer . If you put the recursive call to the last step of function execution , Then finish this step , The stack frame of this function will be released , The new stack frame of the calling function will replace the previous stack frame , So no matter how many times the depth of the call is , Will only occupy a stack frame , Then there will be no stack overflow problem . This is tail recursion .
The key : The precondition is that nothing will be executed after the call , Therefore, what needs to be passed must be passed through parameter design in advance
for example :
and ![]()
The first is to multiply after each call n, there res It plays the same role , Due to tail recursion, the stack frame of each layer should be released , So pass res As a multiplication process
3. Modify stack heap size :
python of use threading To carry out :
if __name__ == '__main__':
threading.stack_size(200000000)
thread = threading.Thread(target=your_code)
thread.start()边栏推荐
- Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
- Unity script API - time class
- Stress, anxiety or depression? Correct diagnosis and retreatment
- Width accuracy
- Rearrange array
- Enter the width!
- Blood cases caused by Lombok use
- Unity script API - component component
- Introduction of text mining tools [easy to understand]
- Quelles sont les perspectives de l'Internet intelligent des objets (aiot) qui a explosé ces dernières années?
猜你喜欢

MySQL index optimization

数据湖治理:优势、挑战和入门

MySQL学习笔记——数据类型(2)

Hidden communication tunnel technology: intranet penetration tool NPS

Big God explains open source buff gain strategy live broadcast

Common knowledge of unity Editor Extension

MySQL学习笔记——数据类型(数值类型)

Game theory

Nine CIO trends and priorities in 2022

Blood cases caused by Lombok use
随机推荐
Stew in disorder
How did the beyond concert 31 years ago get super clean and repaired?
函数式接口,方法引用,Lambda实现的List集合排序小工具
Intranet penetrating FRP: hidden communication tunnel technology
Go deep into the details of deconstruction and assignment of several data types in JS
案例分享|金融业数据运营运维一体化建设
Common API day03 of unity script
Ten clothing stores have nine losses. A little change will make you buy every day
[hcie TAC] question 5 - 1
What should ABAP do when it calls a third-party API and encounters garbled code?
unity update 协程_Unity 协程的原理
Unity script API - GameObject game object, object object
Unity script API - transform transform
JS to realize the countdown function
Unity脚本API—GameObject游戏对象、Object 对象
Unity script introduction day01
Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
Unity脚本介绍 Day01
Unity动画Animation Day05
Detailed explanation of MySQL composite index (multi column index) use and optimization cases