Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#1 basictypes crashes when psyco is enabled


Hi, when importing a module that uses starpy (which uses basictypes), I get the following exception if the use of psyco is enabled (e.g. psyco.profile() has been called):

File "/opt/castdot/castdaemon/brains/callbroker_callflows.py", line 16, in <module>
from starpy import fastagi, utilapplication
File "/usr/lib/python2.5/site-packages/starpy/utilapplication.py", line 2, in <module>
from basicproperty import common, propertied, basic, weak
File "/usr/lib/python2.5/site-packages/basicproperty-0.6.9a-py2.5-linux-i686.egg/basicproperty/common.py", line 9, in <module>
from basictypes import basic_types, list_types, typeunion, decimaldt
File "/usr/lib/python2.5/site-packages/basicproperty-0.6.9a-py2.5-linux-i686.egg/basictypes/list_types.py", line 218, in <module>
dataType = "list.str",
File "/usr/lib/python2.5/site-packages/basicproperty-0.6.9a-py2.5-linux-i686.egg/basictypes/list_types.py", line 92, in __new__
stack = inspect.stack(1)
File "inspect.py", line 885, in stack
return getouterframes(sys._getframe(1), context)
File "inspect.py", line 866, in getouterframes
framelist.append((frame,) + getframeinfo(frame, context))
File "inspect.py", line 835, in getframeinfo
raise TypeError('arg is not a frame or traceback object')
exceptions.TypeError: arg is not a frame or traceback object

It looks like this is due to psyco's psuedo-frame object implementation. From http://psyco.sourceforge.net/psycoguide/bugs.html:
Frame objects are emulated. The sys._getframe function returns an instance of a custom class which emulates the standard frame objects' behavior as much as possible. The frames corresponding to a Psyco-accelerated frame have some placeholder attributes, notably f_locals. There is no way to read the local variables of a Psyco-accelerated frame. Actually, only the f_code, f_globals, f_back and f_lineno fields are well-tested. Also keep in mind that if you obtain a real frame object (which you can do with some other mean than sys._getframe, e.g. via a traceback object), the f_back chained list will not include the Psyco-accelerated frames.

Also see http://mail.python.org/pipermail/python-list/2004-June/267020.html

This error is triggered by the stack inspection code in list_Types.py:

    baseObject = super\( listof, cls\).\_\_new\_\_\( cls, name, bases, named \)
    baseObject.baseType  = baseType
    \#\# Following is the code to try and figure out the
    \#\# module in which the class should reside, this is
    \#\# fragile, as there might be some code that doesn't
    \#\# setup the class in the root of the module.  Like
    \#\# any other class, that class will be unpickle-able.
    stack = inspect.stack\(1\)
    module = stack\[1\]\[0\].f\_globals\['\_\_name\_\_'\]
    baseObject.\_\_module\_\_ = module

I have no experience with basictypes, but I was wondering if there was an alternative approach to figure out the module in which the class should reside (as the above code is trying to do), without having to resort to the use of inspect. That code could possibly be used in an except block if the above method fails. Possibly there is a way to still use inspect, but to get a hold of the original, non-accelerated frames.




  • Logged In: NO

    Oh, btw my email address is robbyd at sent.com