[ZODB-Dev] Unique Object ID

James Oakley jfunk at funktronics.ca
Sat Jun 7 14:15:01 EDT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On June 4, 2003 05:49 pm, Johan Dahlin wrote:
> We've been running into a issue here while developing IndexedCatalog.
> IndexedCatalog stores information about it's objects (which always are
> inherited from a special class) in a OOBTree.
> They are keyed by the id of the object. In the current invocation of
> IndexedCatalog we have been using id() of the object (eg the memory
> address) as the id of the object.
>
> Recently we have found out that it's not very reliable, since it might
> create conflicts if the same memory address is returned when creating
> objects. So we need to find out a reliable way of creating a object id.
...snip...

Here's what I do:

id = long(time.time())*1000+random.randint(0,999)

Unless you're generating a lot of objects in a short time, this should be ok.

- -- 
James Oakley
jfunk at funktronics.ca
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)

iD8DBQE+4g+KKtn0F7+/lLMRAjg7AJ4tlK9AUQtfI3Psi6dL7hQv3IU0/gCggZa2
S27GTI6vwbD2aHGPXpvCyM8=
=5RLa
-----END PGP SIGNATURE-----




More information about the ZODB-Dev mailing list