# Reload py script when use Cross-Language Programming

**URL:** <https://discuss.ray.io/t/reload-py-script-when-use-cross-language-programming/11290>\
**Category:** Ray Client\
**Created:** [July 6, 2023, 8:27am UTC](https://discuss.ray.io/t/reload-py-script-when-use-cross-language-programming/11290 "2023-07-06T08:27:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![imperio-wxm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/imperio-wxm/32/4657_2.png) [@imperio-wxm](https://discuss.ray.io/u/imperio-wxm)\
**Post date:** [July 6, 2023, 8:27am UTC](https://discuss.ray.io/t/reload-py-script-when-use-cross-language-programming/11290/1 "2023-07-06T08:27:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![imperio-wxm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/imperio-wxm/32/4657_2.png) [@imperio-wxm](https://discuss.ray.io/u/imperio-wxm)\
**Post date:** [July 10, 2023, 2:38am UTC](https://discuss.ray.io/t/reload-py-script-when-use-cross-language-programming/11290/2 "2023-07-10T02:38:46Z")

</div>

Can anyone answer this question?

---

<div class="post-metadata">

**Author:** ![jjyao](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jjyao/32/1799_2.png) [@jjyao](https://discuss.ray.io/u/jjyao)\
**Post date:** [July 11, 2023, 5:36am UTC](https://discuss.ray.io/t/reload-py-script-when-use-cross-language-programming/11290/3 "2023-07-11T05:36:16Z")

</div>

@GuyangSong Do you have any ideas?

---

<div class="post-metadata">

**Author:** ![jjyao](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jjyao/32/1799_2.png) [@jjyao](https://discuss.ray.io/u/jjyao)\
**Post date:** [July 11, 2023, 5:36am UTC](https://discuss.ray.io/t/reload-py-script-when-use-cross-language-programming/11290/4 "2023-07-11T05:36:56Z")

</div>

@imperio-wxm Do you have some code snippet that we can take a look?

---

<div class="post-metadata">

**Author:** ![GuyangSong](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/guyangsong/32/181_2.png) [@GuyangSong](https://discuss.ray.io/u/GuyangSong)\
**Post date:** [July 11, 2023, 6:15am UTC](https://discuss.ray.io/t/reload-py-script-when-use-cross-language-programming/11290/5 "2023-07-11T06:15:23Z")

</div>

@imperio-wxm We need to know the running way of your ray job and the details of your code.

---

<div class="post-metadata">

**Author:** ![imperio-wxm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/imperio-wxm/32/4657_2.png) [@imperio-wxm](https://discuss.ray.io/u/imperio-wxm)\
**Post date:** [July 21, 2023, 2:59am UTC](https://discuss.ray.io/t/reload-py-script-when-use-cross-language-programming/11290/6 "2023-07-21T02:59:20Z")

</div>

Just an example from the official docs.

```auto
# /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

```

```auto
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:

```auto
# 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.
