I have a java service,use Cross-Language Programming to execute py remote function.
When I modify the py script, ray will not reload the py script. I feel that the cache is used, and the modified content will not be submitted to the ray cluster. The old py script is still used. Even if I delete the local py script, it can still run successfully.
How to dynamically load the py script without restarting the java service, and use the latest version for each execution?
# /path/to/the_dir/ray_demo.py
# version 1
import ray
@ray.remote
class Counter(object):
def __init__(self):
self.value = 0
def increment(self):
self.value += 1
return self.value
@ray.remote
def add(a, b):
return a + b
public static void test() {
// Set the code-search-path to the directory of your `ray_demo.py` file.
System.setProperty("ray.job.code-search-path", "/path/to/the_dir/");
if (!Ray.isInitialized()) {
Ray.init();
}
// Define a Python class.
PyActorClass actorClass = PyActorClass.of(
"ray_demo", "Counter");
// Create a Python actor and call actor method.
PyActorHandle actor = Ray.actor(actorClass).remote();
ObjectRef objRef1 = actor.task(
PyActorMethod.of("increment", int.class)).remote();
Assert.assertEquals(objRef1.get(), 1);
ObjectRef objRef2 = actor.task(
PyActorMethod.of("increment", int.class)).remote();
Assert.assertEquals(objRef2.get(), 2);
actor.kill();
// Call the Python remote function.
ObjectRef objRef3 = Ray.task(PyFunction.of(
"ray_demo", "add", int.class), 1, 2).remote();
Assert.assertEquals(objRef3.get(), 3);
}
Running the test() method works, At this time, the java program and java client are not shutdown.
Modify the py file:
# version 2
import ray
@ray.remote
class Counter(object):
def __init__(self):
self.value = 0
def increment(self):
self.value += 2
print(self.value)
return self.value
@ray.remote
def add(a, b):
return (a + b ) * 2
The py code before modification is still used, the first version of the code has been cached, and the newly modified code does not take effect.Even if I delete this file ray_demo.py, the program can still run normally.