max*_*max 5 python stack language-implementation python-3.x
根据文档:
\n\n\n\n\n\n\n
inspect.currentframe()返回调用者\xe2\x80\x99s 堆栈\n 帧的帧对象。
\n\nCPython 实现细节:此函数依赖于解释器中的 Python 堆栈框架支持,但不能保证在所有 Python 实现中都存在该支持。如果在没有 Python 堆栈框架支持的实现中运行,则此函数返回 None。
\n
怎么只有这个函数被标记为“依赖于实现”?如果这个功能不行的话,类似的功能,比如inspect.trace、inspect.stack等不是也无法使用吗?
另外,“堆栈框架支持”是什么意思,为什么它会缺失?
\n的可用性与inspect.currentframe以下因素相关sys._getframe:
def currentframe():
"""Return the frame of the caller or None if this is not possible."""
return sys._getframe(1) if hasattr(sys, "_getframe") else None
Run Code Online (Sandbox Code Playgroud)
因此,该限制适用于也使用 的所有其他函数sys._getframe。对于inspect,这仅是inspect.stack。
相反,inspect.trace使用sys.exc_info. 这是异常处理方案的一个组成部分,并且应该始终可用。所有其他相关功能,例如getframeinfo,已经依赖于框架的存在。它们的适用性取决于您是否想要检查异常或调用回溯。
请注意,我的本地默认 jython确实支持sys._getframe. 如果使用 .ipy 运行,ipy 就可以工作-X:Frames。
| 归档时间: |
|
| 查看次数: |
2365 次 |
| 最近记录: |