Containers

Example of creating a container:

1import pdc
2
3with pdc.ServerContext() as _:
4   #make a container.  The container is persistent by default.
5   cont = pdc.Container('persistent_cont')
6
7   #make a transient container, it will be deleted when the pdc server is closed
8   cont2 = pdc.Container('transient_cont', lifetime=pdc.Container.Lifetime.TRANSIENT)
class pdc.Container(self, name: str, lifetime: Lifetime = Lifetime.PERSISTENT)
Containers can contain one or more objects, and objects can be part of one or more containers.
Containers can be used to allow objects to persist, and have no other functionality at the moment.
Every object must be created belonging to a container.

Containers are not namespaces for objects! Objects in different containers must have different names.
Parameters:
  • name (str) – the name of the container. Container names should be unique between all processes that use PDC.

  • lifetime (Lifetime) – the container’s lifetime.

class Lifetime(value)

Bases: Enum

The possible lifetimes of containers.

Lifetime.PERSISTENT

The container and all objects in it will persist across server restarts.

Lifetime.TRANSIENT

The container and all objects in it will be deleted when the server restarts.

all_local_objects() Iterable[pdc.Object]

Get an iterable through all objects in this container that have been retrieved by the client, and haven’t yet been garbage collected. Deleting an object while this iterator is in use may cause undefined behavior.

Returns:

An iterable of Objects

create_object(name: unicode, properties: Object.Properties)

Create a new object, placed in this container. To get an existing object, use Object.get() instead

Parameters:
  • name (str) – the name of the object. Object names should be unique between all processes that use PDC, however, passing in a duplicate name will create the object anyway.

  • properties (ObjectProperties) – An ObjectProperties describing the properties of the object.

classmethod get(name: unicode) Container

Get an existing container by name. If you try to get a container that does not exist, the server segfaults and the call blocks indeinitely.

Parameters:

name (str) – the name of the container.

Returns:

The container.

property lifetime: Lifetime

The lifetime of this container. read-only.

property name: unicode

The name of this container. read-only

object_from_array(self, name: str, array, type: Optional[Type] = None, prop: Optional['Object.Properties'] = None)

Create a new object, placed in this container, from an array-like object. To get an existing object, use Object.get() instead

Parameters:
  • name (str) – the name of the object. Object names should be unique between all processes that use PDC, however, passing in a duplicate name will create the object anyway.

  • array – the array to create the object from. It must be a numpy array, or be convertible to a numpy array via numpy.array().

  • type – If specified, the resulting object will have this type, if all elements of the array fit in this type.

  • prop – If specified, the app name, time step, and user id will be copied from this properties object to the resulting object’s properties.

persist() None

Make this container persistent if it wasn’t already.

property tags: KVTags

The tags of this container. See KVTags for more information.

NOTE: currently, deleting tags from containers is not supported.

pdc.all_local_containers()

Get an iterable of all containers that have been retrieved by the client, and haven’t yet been garbage collected. Deleting a container after this function is called, then using the iterator may cause undefined behavior.

Returns:

An iterable of Containers