sys_getframe3.py 362 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import sys

def f():
    fr = sys._getframe(0)

    print fr.f_lineno
    print fr.f_lineno
    print sorted(fr.f_locals.keys())
    a = 1
    print sorted(fr.f_locals.keys())
f()

assert sys._getframe(0) is sys._getframe(0)

def f2():
    f1 = sys._getframe(0)

    # trigger osr:
    for i in xrange(20000):
        pass
    assert f1 is sys._getframe(0)
f2()