Base object classes

Implements ObjectID base class and global object registry.

It used to be that we could store the HDF5 identifier in an ObjectID and simply close it when the object was deallocated. However, since HDF5 1.8.5 they have started recycling object identifiers, which breaks this system.

We now use a global registry of object identifiers. This is implemented via a dictionary which maps an integer representation of the identifier to a weak reference of an ObjectID. There is only one ObjectID instance in the universe for each integer identifier. When the HDF5 reference count for a identifier reaches zero, HDF5 closes the object and reclaims the identifier. When this occurs, the identifier and weak reference must be deleted from the registry. If an ObjectID is deallocated, it is deleted from the registry and the HDF5 reference count is decreased, HDF5 closes and reclaims the identifier for future use.

All interactions with the registry must be synchronized for thread safety. You must acquire “registry.lock” before interacting with the registry. The registry is not internally synchronized, in the interest of performance: we don’t want the same thread attempting to acquire the lock multiple times during a single operation, if we can avoid it.

All ObjectIDs and subclasses thereof should be opened with the “open” classmethod factory function, such that an existing ObjectID instance can be returned from the registry when appropriate.

class h5py._objects.ObjectID

Represents an HDF5 identifier.

Previous topic

Low-Level API Reference

Next topic

Module H5

This Page