Class PyFunction<R>

java.lang.Object
io.ray.api.function.PyFunction<R>

public class PyFunction<R> extends Object
A class that represents a Python remote function.
 example_package/
 ├──__init__.py
 └──example_module.py

 in example_module.py there is a function.

 \@ray.remote
 def bar(v):
     return v

 then we can call the Python function bar:

 
 // bar returns input, so we have to set the returnType to int.class if bar accepts an int
 ObjectRef<Integer> res = actor.call(
    PyFunction.of("example_package.example_module", "bar", Integer.class),
    1);
 Integer value = res.get();

 // bar returns input, so we have to set the returnType to String.class if bar accepts a string
 ObjectRef<String> res = actor.call(
    PyFunction.of("example_package.example_module", "bar", String.class),
    "Hello world!");
 String value = res.get();
 
 
  • Field Details

    • moduleName

      public final String moduleName
    • functionName

      public final String functionName
    • returnType

      public final Class<R> returnType
  • Method Details

    • of

      public static PyFunction<Object> of(String moduleName, String functionName)
      Create a python function.
      Parameters:
      moduleName - The full module name of this function
      functionName - The name of this function
      Returns:
      a python function.
    • of

      public static <R> PyFunction<R> of(String moduleName, String functionName, Class<R> returnType)
      Create a python function.
      Type Parameters:
      R - Type of the return value of this function
      Parameters:
      moduleName - The full module name of this function
      functionName - The name of this function
      returnType - Class of the return value of this function
      Returns:
      a python function.