Two versions of the same class

Grant Beasley gbeasley at tsa.ac.za
Wed Jan 30 02:30:55 EST 2002


Hi

Firstly, I'm not sure whether this is a mod_python bug / feature or a Python
bug / feature.

The "anomaly" is happening between two separate HTTP connections. On the
first connection, I instantiate an object and store it in a dictionary. If I
test whether instance.__class__ = CLASS (the class I instantiated from), it
returns true, i.e It is the identical class at the same memory location. On
the second connection, I retrieve that instance from the dictionary (the
dictionary is global and maintained between connections). When I retrieve
instance.__class__, the class is identical to the above class, and is
located at the same place in memory, but now the newly "loaded" class is
located at a different memory location.

i.e on first connection:
Instance = <Widget instance at 0x039BCF64>
Instance.__class__ = <class Widget at 0x039EAB1C>
Widget = <class Widget at 0x039EAB1C>

on second connection:
Instance = <Widget instance at 0x039BCF64>
Instance.__class__ = <class Widget at 0x039EAB1C><
Widget = <class Widget at 0x039A72AC>

So although mod_python and Python are keeping my instance in memory (and in
the same place) and the class in memory between connections, on the second
connection it has no reference to the previous class, so it appears to
create a new one.

The effect of this whole jumble is that the Python function
isinstance(Instance, Widget) is returning true on the first connection and
false on the next, and because this function is used internally, I'm getting
a TypeError exception on the second connection - TypeError: unbound method
properties() must be called with Content instance as first argument (got
Link instance instead), when actually the Link class inherits from the
Content class. This is raised when calling Content.properties(self), inside
the Link classes property method.

Environment (if it's relevant):
    Win32
    Python 2.2a (ActivePython)
    Apache 1.3.23
    mod_python 2.7.6

Hope that makes sense.

Thanks
Grant Beasley





More information about the Python-list mailing list