def _initialize_serialization(driver_id, worker=global_worker):
    """Initialize the serialization library.

    This defines a custom serializer for object IDs and also tells ray to
    serialize several exception classes that we define for error handling.
    """
    serialization_context = pyarrow.default_serialization_context()
    # Tell the serialization context to use the cloudpickle version that we
    # ship with Ray.
    serialization_context.set_pickle(pickle.dumps, pickle.loads)
    pyarrow.register_torch_serialization_handlers(serialization_context)

    for id_type in ray._raylet._ID_TYPES:
        serialization_context.register_type(
            id_type,
            "{}.{}".format(id_type.__module__, id_type.__name__),
            pickle=True)

    def actor_handle_serializer(obj):
        return obj._serialization_helper(True)

    def actor_handle_deserializer(serialized_obj):
        new_handle = ray.actor.ActorHandle.__new__(ray.actor.ActorHandle)
        new_handle._deserialization_helper(serialized_obj, True)
        return new_handle

    # We register this serializer on each worker instead of calling
    # register_custom_serializer from the driver so that isinstance still
    # works.
    serialization_context.register_type(
        ray.actor.ActorHandle,
        "ray.ActorHandle",
        pickle=False,
        custom_serializer=actor_handle_serializer,
        custom_deserializer=actor_handle_deserializer)

    worker.serialization_context_map[driver_id] = serialization_context

    # Register exception types.
    for error_cls in RAY_EXCEPTION_TYPES:
        register_custom_serializer(
            error_cls,
            use_dict=True,
            local=True,
            driver_id=driver_id,
            class_id=error_cls.__module__ + ". " + error_cls.__name__,
        )
    # Tell Ray to serialize lambdas with pickle.
    register_custom_serializer(
        type(lambda: 0),
        use_pickle=True,
        local=True,
        driver_id=driver_id,
        class_id="lambda")
    # Tell Ray to serialize types with pickle.
    register_custom_serializer(
        type(int),
        use_pickle=True,
        local=True,
        driver_id=driver_id,
        class_id="type")
    # Tell Ray to serialize FunctionSignatures as dictionaries. This is
    # used when passing around actor handles.
    register_custom_serializer(
        ray.signature.FunctionSignature,
        use_dict=True,
        local=True,
        driver_id=driver_id,
        class_id="ray.signature.FunctionSignature")
def _initialize_serialization ( driver_id , worker = global_worker ) : serialization_context = pyarrow . default_serialization_context ( ) serialization_context . set_pickle ( pickle . dumps , pickle . loads ) pyarrow . register_torch_serialization_handlers ( serialization_context ) for id_type in ray . _raylet . _ID_TYPES : serialization_context . register_type ( id_type , "{}.{}" . format ( id_type . __module__ , id_type . __name__ ) , pickle = True ) def actor_handle_serializer ( obj ) : return obj . _serialization_helper ( True ) def actor_handle_deserializer ( serialized_obj ) : new_handle = ray . actor . ActorHandle . __new__ ( ray . actor . ActorHandle ) new_handle . _deserialization_helper ( serialized_obj , True ) return new_handle serialization_context . register_type ( ray . actor . ActorHandle , "ray.ActorHandle" , pickle = False , custom_serializer = actor_handle_serializer , custom_deserializer = actor_handle_deserializer ) worker . serialization_context_map [ driver_id ] = serialization_context for error_cls in RAY_EXCEPTION_TYPES : register_custom_serializer ( error_cls , use_dict = True , local = True , driver_id = driver_id , class_id = error_cls . __module__ + ". " + error_cls . __name__ , ) register_custom_serializer ( type ( lambda : 0 ) , use_pickle = True , local = True , driver_id = driver_id , class_id = "lambda" ) register_custom_serializer ( type ( int ) , use_pickle = True , local = True , driver_id = driver_id , class_id = "type" ) register_custom_serializer ( ray . signature . FunctionSignature , use_dict = True , local = True , driver_id = driver_id , class_id = "ray.signature.FunctionSignature" )
Initialize the serialization library.

    This defines a custom serializer for object IDs and also tells ray to
    serialize several exception classes that we define for error handling.