コード例 #1
0
def workflow_logging_context(job_id) -> None:
    """Initialize the workflow logging context.

    Workflow executions are running as remote functions from
    WorkflowManagementActor. Without logging redirection, workflow
    inner execution logs will be pushed to the driver that initially
    created WorkflowManagementActor rather than the driver that
    actually submits the current workflow execution.
    We use this conext manager to re-configure the log files to send
    the logs to the correct driver, and to restore the log files once
    the execution is done.

    Args:
        job_id: The ID of the job that submits the workflow execution.
    """
    node = ray._private.worker._global_node
    original_out_file, original_err_file = node.get_log_file_handles(
        get_worker_log_file_name("WORKER"))
    out_file, err_file = node.get_log_file_handles(
        get_worker_log_file_name("WORKER", job_id))
    try:
        configure_log_file(out_file, err_file)
        yield
    finally:
        configure_log_file(original_out_file, original_err_file)
コード例 #2
0
ファイル: default_worker.py プロジェクト: yncxcw/ray
    ray.worker._global_node = node
    ray.worker.connect(node, mode=mode, runtime_env_hash=args.runtime_env_hash)

    # Add code search path to sys.path, set load_code_from_local.
    core_worker = ray.worker.global_worker.core_worker
    code_search_path = core_worker.get_job_config().code_search_path
    load_code_from_local = False
    if code_search_path:
        load_code_from_local = True
        for p in code_search_path:
            if os.path.isfile(p):
                p = os.path.dirname(p)
            sys.path.insert(0, p)
    ray.worker.global_worker.set_load_code_from_local(load_code_from_local)

    # Setup log file.
    out_file, err_file = node.get_log_file_handles(
        get_worker_log_file_name(args.worker_type))
    configure_log_file(out_file, err_file)

    if mode == ray.WORKER_MODE:
        ray.worker.global_worker.main_loop()
    elif (mode == ray.RESTORE_WORKER_MODE or mode == ray.SPILL_WORKER_MODE
          or mode == ray.UTIL_WORKER_MODE):
        # It is handled by another thread in the C++ core worker.
        # We just need to keep the worker alive.
        while True:
            time.sleep(100000)
    else:
        raise ValueError(f"Unexcepted worker mode: {mode}")