鱼C论坛

 找回密码
 立即注册
查看: 1926|回复: 2

[已解决]python 递归之后 IDLE restart 了

[复制链接]
发表于 2020-2-7 19:14:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 一个账号 于 2020-3-16 18:38 编辑



为什么会 restart 呢?

1.png

  1. Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
  2. Type "help", "copyright", "credits" or "license()" for more information.
  3. >>> import sys
  4. >>> sys.setrecursionlimit(999999)
  5. >>> def test():
  6.         test()

  7.        
  8. >>> test()

  9. ================================ RESTART: Shell ================================
  10. >>> import sys
  11. >>> sys.setrecursionlimit(9999999)
  12. >>> def test():
  13.         test()

  14.        
  15. >>> test()
  16. Traceback (most recent call last):
  17.   File "<pyshell#11>", line 1, in <module>
  18.     test()
  19.   File "<pyshell#10>", line 2, in test
  20.     test()
  21.   File "<pyshell#10>", line 2, in test
  22.     test()
  23.   File "<pyshell#10>", line 2, in test
  24.     test()
  25.   [Previous line repeated 7614 more times]
  26. MemoryError: Stack overflow
  27. >>> test()
  28. Traceback (most recent call last):
  29.   File "<pyshell#12>", line 1, in <module>
  30.     test()
  31.   File "<pyshell#10>", line 2, in test
  32.     test()
  33.   File "<pyshell#10>", line 2, in test
  34.     test()
  35.   File "<pyshell#10>", line 2, in test
  36.     test()
  37.   [Previous line repeated 7622 more times]
  38. MemoryError: Stack overflow
  39. >>> while True:
  40.         try:
  41.                 test()
  42.         except:
  43.                 continue

  44.        

  45. ======================================================================= RESTART: Shell ======================================================================
复制代码
最佳答案
2020-2-7 20:35:02
本帖最后由 一个账号 于 2020-3-16 18:38 编辑

第一遍错误:无法复现,应该是和第二次错误原因相同,堆栈溢出

系统和编译器栈大小默认为1M吧,超过1M就会栈溢出,所以应该只能调低递归深度解决

学识浅薄希望对你有所帮助
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-2-7 20:35:02 | 显示全部楼层    本楼为最佳答案   
本帖最后由 一个账号 于 2020-3-16 18:38 编辑

第一遍错误:无法复现,应该是和第二次错误原因相同,堆栈溢出

系统和编译器栈大小默认为1M吧,超过1M就会栈溢出,所以应该只能调低递归深度解决

学识浅薄希望对你有所帮助
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-6 02:34

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表