[Twisted-Python] Re: can pb.Copyable objects be compared for equality after a round trip?

David Bolen db3l at fitlinxx.com
Mon Jun 26 10:56:27 MDT 2006


Robert Gravina <robert at gravina.com> writes:

> Ah sorry everyone... it seems I've misunderstood a very basic concept:
> 
> Copyables are copy-by-value
> Referenceables are copy-by-reference
> 
> It says so here:
> http://www.lothar.com/tech/papers/PyCon-2003/pb-pycon/pb.html
> 
> So basically I need to use either Referenceable or Viewable! OK now I
> can get back to work.

Well, or just define your own comparison semantics in your copyable,
as you might for any other object.  We use copyables all the time for
precisely this pattern (return object remotely, edit it, re-use it in
a subsequent call back to the server) and it works fine as long as you
control the comparison and don't fall back to default Python rules,
which for class instances is effectively just an id() comparison.

As it turns out, we do also embed an "_id" attribute within the
objects (an auto-generated UUID) so we can detect collisions
(two clients attempting to modify the same object), but for general
comparison purposes outside of that collision check, we exclude the
_id attribute.

-- David





More information about the Twisted-Python mailing list