当前位置:网站首页>[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()边栏推荐
- mysql 联合主键_Mysql 创建联合主键[通俗易懂]
- 2022年九大CIO趨勢和優先事項
- MySQL learning notes - data type (numeric type)
- . Net applications consider x64 generation
- Function test - knowledge points and common interview questions
- 深入JS中几种数据类型的解构赋值细节
- [tutorial] yolov5_ DeepSort_ The whole process of pytoch target tracking and detection
- Working group and domain analysis of Intranet
- Explore mongodb - mongodb compass installation, configuration and usage introduction | mongodb GUI
- Preliminary practice of niuke.com (10)
猜你喜欢

lnx 高效搜索引擎、FastDeploy 推理部署工具箱、AI前沿论文 | ShowMeAI资讯日报 #07.04

Redis' optimistic lock and pessimistic lock for solving transaction conflicts

MySQL index optimization
Redis shares four cache modes

QT graphical view frame: element movement

Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database

Case sharing | integrated construction of data operation and maintenance in the financial industry

2022年九大CIO趨勢和優先事項

Overview of convolutional neural network structure optimization

AI做题水平已超过CS博士?
随机推荐
Case sharing | integrated construction of data operation and maintenance in the financial industry
Unity script API - time class
Unity prefab day04
在芯片高度集成的今天,绝大多数都是CMOS器件
Unity脚本API—Component组件
Move, say goodbye to the past again
The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release
Width accuracy
LNX efficient search engine, fastdeploy reasoning deployment toolbox, AI frontier paper | showmeai information daily # 07.04
Functional interface, method reference, list collection sorting gadget implemented by lambda
Big God explains open source buff gain strategy live broadcast
MySQL index optimization
odoo数据库主控密码采用什么加密算法?
Data Lake Governance: advantages, challenges and entry
%F format character
MYSQL索引优化
Stress, anxiety or depression? Correct diagnosis and retreatment
Unity脚本生命周期 Day02
Stew in disorder
Model fusion -- stacking principle and Implementation