您的位置:首页 > 编程语言 > Python开发

[Python] RuntimeError: maximum recursion depth exceeded|MemoryError: stack overflow 递归|堆栈限制

2018-01-05 11:16 1391 查看
递归限制:

RuntimeError: maximum recursion depth exceeded

python默认的递归深度是很有限的,大概是900多的样子,当递归深度超过这个值的时候,就会引发这样的一个异常。

解决的方式是手工设置递归调用深度,方式为

import sys
sys.setrecursionlimit(1000000) #例如这里设置为一百万


参考:http://blog.csdn.net/welber/article/details/6447513

堆栈限制:

Process finished with exit code -1073741571 (0xC00000FD)

MemoryError: stack overflow

import threading
def your_code():
print "1"

if __name__ == '__main__':
threading.stack_size(200000000)
thread = threading.Thread(target=your_code) #your_code是函数
thread.start()


这解决了我的递归限制和我的堆大小限制。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python
相关文章推荐