How safe is recursion in Python?

后端 未结 5 2104
青春惊慌失措
青春惊慌失措 2021-01-22 05:37

I\'m working on an AI homework, and despite my professor\'s suggestions, I have no intention of writing this assignment in lisp. However, I do want to write it recursiv

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-22 05:54

    As others have pointed out, you can increase the recursion depth using sys.setrecursiondepth(), though at the risk of overflowing the C stack (assuming you are using CPython). If you run into this problem, you can create a thread with bigger stack size by calling thread.stack_size() with the new stack size, and then spawn a new thread to do the actual work.

提交回复
热议问题