[Tutor] How to determine which function code is being called from

eryksun eryksun at gmail.com
Fri Mar 7 13:26:58 CET 2014


On Fri, Mar 7, 2014 at 6:45 AM, Danny Yoo <dyoo at hashcollision.org> wrote:
>
> Although many of the recommendations have been discouraging the stack
> inspection approach, even stack inspection might be appropriate,
> though it's certainly not a technique for beginners.

Stack inspection is really intended for debugging or logging. The
stack frame functions in the inspect module really shouldn't be used
for program logic. The warning in the docs about inspect.currentframe
applies equally to inspect.stack. These functions rely on
sys._getframe, which is a CPython implementation detail.

PyPy and Jython do support sys._getframe. IronPython 2.6 added the
command-line options -X:Frames and -X:FullFrames to support
sys._getframe, but its design using the DLR doesn't require frame
objects. Creating them is extra work and probably degrades performance
(definitely for FullFrames).


More information about the Tutor mailing list