[Twisted-Python] Why do I get a _Dereference instance?

Patrik Blommaskog pb_twisted at olga.mine.nu
Sun Jul 6 14:10:33 MDT 2003


Hi list,

I'm using PB to transfer the following structure (with a circular reference)
on the server (cut down, incomplete code from my app) to a client:

class Inventory(pb.Cacheable):
    def __init__(self, ownerActor):
        self.owner = ownerActor

    def getStateToCacheAndObserveFor(self, perspective, observer):
        return {"owner" : self.owner}


class PlayerActor(pb.Cacheable):
    def __init__(self):
	  self.name = "MyName"
        self.inventory = Inventory(self)

    def getStateToCacheAndObserveFor(self, perspective, observer):
        return {"inventory" : self.inventory}


On the client, these classes correspond to RemoteInventory and RemoteActor
respectively.

What ends up on the client is an actor with the following __dict__:

{'inventory': <RemoteInventory.RemoteInventory instance at 0x01CE4DA8>,
'broker': <twisted.spread.pb.Broker instance at 0x01C8D588>, 'luid': 5,
'name': 'MyName'}

As expected. However, the inventory:

{'owner': <twisted.persisted.crefutil._Dereference instance at 0x01C90BE0>,
'broker': <twisted.spread.pb.Broker instance at 0x01C8D588>, 'luid': 6}

My client-side inventory owner attribute refers to a _Dereference object
instead of the actor object. I don't know much about Twisted's Jelly, but it
sounds like something that should be removed automatically at the end of the
de-serialization process.

I notice that I can access my inventory.owner.resolvedObject to get the
actual actor object I want, but I cannot access it directly through the
_Dereference object (e.g. inventory.owner.name) as if though it were a proxy
or something. So why is it there, and can/should I get rid of it?

I am sure there is a logic to this, which I'd be grateful if someone would
like to explain to me or, better yet, point me to some nice bedtime reading
on the subject.


- Patrik






More information about the Twisted-Python mailing list