当前位置:网站首页>[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()边栏推荐
- JS tile data lookup leaf node
- Penetration test --- database security: detailed explanation of SQL injection into database principle
- AI system content recommendation issue 24
- LeetCode 58. Length of the last word
- Unity script API - time class
- Neuf tendances et priorités du DPI en 2022
- Nine CIO trends and priorities in 2022
- Interpretation of the champion scheme of CVPR 2020 night target detection challenge
- Redis' optimistic lock and pessimistic lock for solving transaction conflicts
- 每周招聘|高级DBA年薪49+,机会越多,成功越近!
猜你喜欢

Penetration test --- database security: detailed explanation of SQL injection into database principle

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

AI做题水平已超过CS博士?

每周招聘|高级DBA年薪49+,机会越多,成功越近!
Detailed explanation of MySQL composite index (multi column index) use and optimization cases

Blood cases caused by Lombok use

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

MySQL index optimization

QT graphical view frame: element movement

Intranet penetrating FRP: hidden communication tunnel technology
随机推荐
AI has surpassed Dr. CS in question making?
Unity prefab day04
How was MP3 born?
Case sharing | integrated construction of data operation and maintenance in the financial industry
Redis' optimistic lock and pessimistic lock for solving transaction conflicts
What should ABAP do when it calls a third-party API and encounters garbled code?
Ten clothing stores have nine losses. A little change will make you buy every day
Unity脚本API—Time类
Enter the width!
31年前的Beyond演唱会,是如何超清修复的?
Actual combat | use composite material 3 in application
MySQL index optimization
Interface test - knowledge points and common interview questions
MySQL learning notes - data type (numeric type)
AI做题水平已超过CS博士?
LeetCode 35. Search the insertion position - vector traversal (O (logn) and O (n) - binary search)
Interpretation of the champion scheme of CVPR 2020 night target detection challenge
怎么判断外盘期货平台正规,资金安全?
Summary of database 2
. Net delay queue