[Twisted-Python] pb objects unexpectedly change identity

Daniel Sank sank.daniel at gmail.com
Wed Apr 30 12:00:36 MDT 2014


Dear twisted users,

I think I have found some surprising behavior in perspective broker. I
define a subclass of pb.RemoteCache which has a method managed by a
descriptor. The descriptor keeps track of the instances it manages in a set.

When the RemoteCache is first received by the client, it accesses the
descriptor-ified method inside setCopyableState. At that time the
RemoteCache's id is a certain value X. Then later when the RemoteCache is
notified of a change by the server side Cacheable, it again accesses the
descriptor-ified method, but at this time it's id is Y, and Y!=X.

I attach to this post a simple working example which displays the behavior
described above. To run, first run server.py and then run client.py. You
will see a little bit of output, the most important part being

===
Client received RemoteCache: id=45952496

Asking server to update
TD 45921680 (test.RemoteCache.add) accessed by <test.RemoteCache instance
at 2BD2DC8>: id=45952456
RemoteCache id=45952496
===

To understand the details of the output please see descriptor.py. The id of
the RemoteCache is first reported as 45952496 when the client receives it.
Then, when the descriptor is accessed, the id of the accessing instance is
reported as 45952456, which is different. Then, when in the last line we
print out the id of the RemoteCache we're back to 45952496.

Is there some reason that a RemoteCache's id can change during its life
time?

-- 
Daniel Sank
Department of Physics
Broida Hall
University of California
Santa Barbara, CA 93117
(805)893-3899
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140430/a30c95f0/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: server.py
Type: text/x-python
Size: 442 bytes
Desc: not available
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140430/a30c95f0/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: resources.py
Type: text/x-python
Size: 3455 bytes
Desc: not available
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140430/a30c95f0/attachment-0001.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: client.py
Type: text/x-python
Size: 202 bytes
Desc: not available
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140430/a30c95f0/attachment-0002.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: descriptor.py
Type: text/x-python
Size: 553 bytes
Desc: not available
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140430/a30c95f0/attachment-0003.py>


More information about the Twisted-Python mailing list