run_function_on_all_workers only once in the driver (#15203)

This commit is contained in:
Siyuan (Ryans) Zhuang 2021-04-15 13:58:36 -07:00 committed by GitHub
parent eaa3ce3f40
commit 4de1f35b3e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -159,10 +159,10 @@ class ImportThread:
run_on_other_drivers) = self.redis_client.hmget(
key, ["job_id", "function", "run_on_other_drivers"])
if (ray._private.utils.decode(run_on_other_drivers) == "False"
and self.worker.mode == ray.SCRIPT_MODE
and job_id != self.worker.current_job_id.binary()):
return
if self.worker.mode == ray.SCRIPT_MODE:
if (run_on_other_drivers == b"False"
or job_id == self.worker.current_job_id.binary()):
return
try:
# FunctionActorManager may call pickle.loads at the same time.

View file

@ -145,6 +145,11 @@ def test_running_function_on_all_workers(ray_start_regular):
assert "fake_directory" == ray.get(get_path1.remote())[-1]
# the function should only run on the current driver once.
assert sys.path[-1] == "fake_directory"
if len(sys.path) > 1:
assert sys.path[-2] != "fake_directory"
def f(worker_info):
sys.path.pop(-1)