当前位置:网站首页>[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()
边栏推荐
- [book club issue 13] ffmpeg common methods for viewing media information and processing audio and video files
- Intranet penetrating FRP: hidden communication tunnel technology
- Summary of database 2
- . Net applications consider x64 generation
- 干货 | fMRI标准报告指南新鲜出炉啦,快来涨知识吧
- What does IOT engineering learn and work for?
- Usage of database functions "recommended collection"
- The per capita savings of major cities in China have been released. Have you reached the standard?
- Understand the context in go language in an article
- Proxifier global agent software, which provides cross platform port forwarding and agent functions
猜你喜欢
科研漫画 | 联系到被试后还需要做什么?
What is the catalog of SAP commerce cloud
Audio and video technology development weekly | 252
Data Lake Governance: advantages, challenges and entry
MySQL index optimization
2022年九大CIO趨勢和優先事項
Blood cases caused by Lombok use
The per capita savings of major cities in China have been released. Have you reached the standard?
How was MP3 born?
Function test - knowledge points and common interview questions
随机推荐
Common API day03 of unity script
Case sharing | integrated construction of data operation and maintenance in the financial industry
Lombok使用引发的血案
Game theory
AI做题水平已超过CS博士?
mysql 联合主键_Mysql 创建联合主键[通俗易懂]
[book club issue 13] coding format of video files
Unity script API - transform transform
LeetCode 58. Length of the last word
Intranet penetrating FRP: hidden communication tunnel technology
Redis' optimistic lock and pessimistic lock for solving transaction conflicts
Feature extraction and detection 15-akaze local matching
Unity脚本API—GameObject游戏对象、Object 对象
Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
An article learns variables in go language
Enter the width!
Book of night sky 53 "stone soup" of Apache open source community
How did the beyond concert 31 years ago get super clean and repaired?
干货 | fMRI标准报告指南新鲜出炉啦,快来涨知识吧
Interface test - knowledge points and common interview questions