当前位置:网站首页>[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()
边栏推荐
- %F format character
- What does IOT engineering learn and work for?
- QT graphical view frame: element movement
- Variable cannot have type 'void'
- Shell programming basics
- Can I "reverse" a Boolean value- Can I 'invert' a bool?
- MySQL federated primary key_ MySQL creates a federated primary key [easy to understand]
- Blood cases caused by Lombok use
- unity update 协程_Unity 协程的原理
- Decimal, exponential
猜你喜欢
error: ‘connect‘ was not declared in this scope connect(timer, SIGNAL(timeout()), this, SLOT(up
LNX efficient search engine, fastdeploy reasoning deployment toolbox, AI frontier paper | showmeai information daily # 07.04
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
[native JS] optimized text rotation effect
A trap used by combinelatest and a debouncetime based solution
What is the catalog of SAP commerce cloud
lnx 高效搜索引擎、FastDeploy 推理部署工具箱、AI前沿论文 | ShowMeAI资讯日报 #07.04
The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release
Data Lake Governance: advantages, challenges and entry
2022年九大CIO趋势和优先事项
随机推荐
Unity脚本API—Component组件
Unity script API - component component
Temperature control system based on max31865
JS to realize the countdown function
Lombok使用引发的血案
Introduction of text mining tools [easy to understand]
MySQL学习笔记——数据类型(2)
AutoCAD - set color
Data Lake Governance: advantages, challenges and entry
Will the memory of ParticleSystem be affected by maxparticles
Common API day03 of unity script
Interpretation of the champion scheme of CVPR 2020 night target detection challenge
error: ‘connect‘ was not declared in this scope connect(timer, SIGNAL(timeout()), this, SLOT(up
MySQL index optimization
Laravel simply realizes Alibaba cloud storage + Baidu AI Cloud image review
Detailed explanation of MySQL composite index (multi column index) use and optimization cases
Weekly recruitment | senior DBA annual salary 49+, the more opportunities, the closer success!
Function test - knowledge points and common interview questions
How can floating point numbers be compared with 0?
压力、焦虑还是抑郁? 正确诊断再治疗