How do I get the current depth of the Python interpreter stack?

前端 未结 2 1732
不思量自难忘°
不思量自难忘° 2020-12-19 02:16

From the documentation:

sys.getrecursionlimit()

Return the current value of the recursion limit, the maximum depth of th

2条回答
  •  时光说笑
    2020-12-19 02:59

    You can see the whole call stack from inspect.stack(), so currently taken depth would be len(inspect.stack(0)).

    On the other hand, I guess you got the complete stack printed out when "maximum recursion depth exceeded" exception was raised. That stack trace should show you exactly what went wrong.

提交回复
热议问题