Python RuntimeError: maximum recursion depth exceeded in cmp 超过最大递归深度错误
2017-02-24 14:52
881 查看
说明:Python运行版本Python2.7.12
最近写了个Python爬虫,运行时出现 RuntimeError: maximum recursion depth exceeded in cmp 错误,上网查资料发现Python遍历深度在最大1000,超过就会报错!
写个程序测试下:
#coding=utf-8
import sys
def func(depth):
depth += 1
print "Now the depth is %d" % depth
func(depth)
if __name__ == "__main__" :
func(0)
结果:
可以看到当递归深度超过999达到1000的时候,引发了这个异常 ,解决的方式是手工设置递归调用深度,方式为:
import
sys
sys.setrecursionlimit(1000000)
#设置为一百万
不过,最好优化程序,这是临时解决办法!
最近写了个Python爬虫,运行时出现 RuntimeError: maximum recursion depth exceeded in cmp 错误,上网查资料发现Python遍历深度在最大1000,超过就会报错!
写个程序测试下:
#coding=utf-8
import sys
def func(depth):
depth += 1
print "Now the depth is %d" % depth
func(depth)
if __name__ == "__main__" :
func(0)
结果:
可以看到当递归深度超过999达到1000的时候,引发了这个异常 ,解决的方式是手工设置递归调用深度,方式为:
import
sys
sys.setrecursionlimit(1000000)
#设置为一百万
不过,最好优化程序,这是临时解决办法!
相关文章推荐
- Python的最大递归深度错误 “maximum recursion depth exceeded while calling a Python object”
- python递归深度报错--RuntimeError: maximum recursion depth exceeded
- python setup.py install 出现了 RuntimeError: maximum recursion depth exceeded in cmp
- python递归深度报错--RuntimeError: maximum recursion depth exceeded
- python递归深度报错: RuntimeError: maximum recursion depth exceeded
- python递归深度报错--RuntimeError: maximum recursion depth exceeded
- python 最大递归次数 RuntimeError: maximum recursion depth exceeded
- 当python超出默认递归次数RecursionError: maximum recursion depth exceeded in comparison
- python RecursionError: maximum recursion depth exceeded in comparison错误
- RuntimeError: maximum recursion depth exceeded 递归深度报错
- [Python] RuntimeError: maximum recursion depth exceeded|MemoryError: stack overflow 递归|堆栈限制
- python递归报错 RuntimeError: maximum recursion depth exceeded
- django启动的时候报错RuntimeError: maximum recursion depth exceeded in cmp
- RuntimeError: maximum recursion depth exceeded in cmp
- RuntimeError: maximum recursion depth exceeded 递归深度报错
- 启动django的服务时候报错RuntimeError: maximum recursion depth exceeded in cmp
- python使用pip安装一个module时报错:RuntimeError: maximum recursion depth exceeded
- Django启动服务器报错:maximum recursion depth exceeded in cmp
- 启动django项目报错:RuntimeError: maximum recursion depth exceeded while calling a Python object
- 爬豆瓣影评,记下解决maximum recursion depth exceeded in cmp