yr.put

Contents

yr.put#

yr.put(obj: object, create_param: ~yr.base_runtime.CreateParam = CreateParam(consistency_type=<ConsistencyType.PRAM: 0>, cache_type=<CacheType.MEMORY: 0>)) ObjectRef[source]#

Put an object to datasystem.

Note

  1. this method should be used after yr.init().

  2. If the type of put is memoryview, bytearray or bytes, serialization is omitted at this time.

  3. If the object passed to put() is of type memoryview, bytearray, or bytes, its length must not be 0.

Parameters:
  • obj (object) – This is a python object, will be pickled and saved to datasystem.

  • create_param (CreateParam) – This is create param for datasystem.

Returns:

the object ref to the object. Data type is ObjectRef.

Raises:
  • ValueError – If the input obj is None or a zero-length bytes, bytearray, or memoryview object.

  • TypeError – If the input obj is already an ObjectRef.

  • TypeError – If the input obj is not serializable, e.g. thread.RLock.

  • RuntimeError – Call yr.put() before yr.init().

  • RuntimeError – Failed to put to datasystem.

Examples

>>> import yr
>>> yr.init()
>>> param = yr.CreateParam()
>>> param.cache_type = yr.CacheType.DISK
>>> bs = bytes(0)
>>> mem = memoryview(bytes(100))
>>> obj_ref2 = yr.put(mem)
>>> print(yr.get(obj_ref2))
>>> # The final print output is a memoryview pointer.
>>> byte_array = bytearray(20)
>>> obj_ref3 = yr.put(byte_array)
>>> print(yr.get(obj_ref3))
>>> # The final print output is a memoryview pointer.
>>> obj_ref4 = yr.put(100)
>>> print(yr.get(obj_ref4))