worker.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:ray-legacy 作者: ray-project 项目源码 文件源码
def run_function_on_all_workers(self, function):
    """Run arbitrary code on all of the workers.

    This function will first be run on the driver, and then it will be exported
    to all of the workers to be run. It will also be run on any new workers that
    register later. If ray.init has not been called yet, then cache the function
    and export it later.

    Args:
      function (Callable): The function to run on all of the workers. It should
        not take any arguments. If it returns anything, its return values will
        not be used.
    """
    if self.mode not in [None, raylib.SCRIPT_MODE, raylib.SILENT_MODE, raylib.PYTHON_MODE]:
      raise Exception("run_function_on_all_workers can only be called on a driver.")
    # First run the function on the driver.
    function(self)
    # If ray.init has not been called yet, then cache the function and export it
    # when connect is called. Otherwise, run the function on all workers.
    if self.mode is None:
      self.cached_functions_to_run.append(function)
    else:
      self.export_function_to_run_on_all_workers(function)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号