Thread: plpython: sys module doesn't know about _getframe

plpython: sys module doesn't know about _getframe

From
pgsql-bugs@postgresql.org
Date:
Steven D. Arnold (stevena@neosynapse.net) reports a bug with a severity of 3
The lower the number the more severe it is.

Short Description
plpython: sys module doesn't know about _getframe

Long Description
I have a module which I import and use in plpython functions.  One function in this module imports sys and then uses
sys._getframe(). When it tries to do this, plpython says: 

exceptions.AttributeError: 'sys' module has no attribute '_getframe'

The same function using Python directly works fine.  Does plpython use a specialized version of Python or a specialized
sysmodule? 

Sample Code
create function foo() returns integer as '
    import data_handler
    result = data_handler.qse("""SELECT * FROM users""")
    return 1
' language 'plpython';

[In module data_handler]
import sys
def qse(s, layers=1):
    loc = sys._getframe(layers).f_locals
    glb = sys._getframe(layers).f_globals
    [...]
    return s


No file was uploaded with this report