[Python-ideas] Standard way to get caller name and easy call stack access

Andrew McNabb amcnabb at mcnabbs.org
Thu Mar 22 18:37:12 CET 2012

On Thu, Mar 22, 2012 at 09:24:40AM +0000, Mark Shannon wrote:
> >If sys._getframe() is not available in Jython, IronPython and PyPy
> >then I won't use that for debug mode output in libraries.
> sys._getframe() is available in PyPy and Jython, I'm not sure if
> IronPython supports it, I think it does.
> A simpler and more concrete suggestion might be to simply rename
> sys._getframe() as sys.getframe(), since all the main implementations
> support it anyway.

Apparently sys._getframe is only partially supported in PyPy. It works
but probably shouldn't be encouraged because it has a huge performance

"sys._getframe(), sys.exc_info() work, but they give performance penalty
that can be huge, by disabling the JIT. Use only for specialized use
cases (like a debugger) where performance does not matter.

"One unobvious usecase where this is used is the logging module. Don't
use logging module if you want things to be fast."


Andrew McNabb
PGP Fingerprint: 8A17 B57C 6879 1863 DE55  8012 AB4D 6098 8826 6868

More information about the Python-ideas mailing list