11"""Distributed Module (PRIVATE)."""
2-
32import logging
43import multiprocessing
54import os
65import sys
76import warnings
87from functools import wraps
9- from typing import TYPE_CHECKING , Any , Callable , List , Optional
8+ from typing import TYPE_CHECKING , Any , Callable , List , Optional , Union
109
1110from awswrangler ._config import apply_configs , config
1211
1918_logger : logging .Logger = logging .getLogger (__name__ )
2019
2120
21+ class RayLogger :
22+ """Create discrete Logger instance for Ray Tasks."""
23+
24+ def __init__ (
25+ self ,
26+ log_level : int = logging .INFO ,
27+ format : str = "%(asctime)s::%(levelname)-2s::%(name)s::%(message)s" , # pylint: disable=redefined-builtin
28+ datefmt : str = "%Y-%m-%d %H:%M:%S" ,
29+ ):
30+ logging .basicConfig (level = log_level , format = format , datefmt = datefmt )
31+
32+ def get_logger (self , name : Union [str , Any ] = None ) -> Union [logging .Logger , Any ]:
33+ """Return logger object."""
34+ return logging .getLogger (name ) if config .distributed else None
35+
36+
2237def ray_get (futures : List [Any ]) -> List [Any ]:
2338 """
2439 Run ray.get on futures if distributed.
@@ -45,7 +60,6 @@ def ray_remote(function: Callable[..., Any]) -> Callable[..., Any]:
4560 ----------
4661 function : Callable[..., Any]
4762 Callable as input to ray.remote
48-
4963 Returns
5064 -------
5165 Callable[..., Any]
@@ -94,6 +108,7 @@ def initialize_ray(
94108 redis_password : Optional [str ] = None ,
95109 ignore_reinit_error : Optional [bool ] = True ,
96110 include_dashboard : Optional [bool ] = False ,
111+ log_to_driver : Optional [bool ] = True ,
97112 object_store_memory : Optional [int ] = None ,
98113 cpu_count : Optional [int ] = None ,
99114 gpu_count : Optional [int ] = 0 ,
@@ -111,6 +126,8 @@ def initialize_ray(
111126 If true, Ray suppress errors from calling ray.init() twice, by default True
112127 include_dashboard : Optional[bool]
113128 Boolean flag indicating whether or not to start the Ray dashboard, by default False
129+ log_to_driver : Optional[bool]
130+ Boolean flag to enable routing of all worker logs to the driver, by default True
114131 object_store_memory : Optional[int]
115132 The amount of memory (in bytes) to start the object store with, by default None
116133 cpu_count : Optional[int]
@@ -124,6 +141,7 @@ def initialize_ray(
124141 address = address ,
125142 include_dashboard = include_dashboard ,
126143 ignore_reinit_error = ignore_reinit_error ,
144+ log_to_driver = log_to_driver ,
127145 )
128146 else :
129147 if not object_store_memory :
@@ -151,6 +169,7 @@ def initialize_ray(
151169 "num_gpus" : gpu_count ,
152170 "include_dashboard" : include_dashboard ,
153171 "ignore_reinit_error" : ignore_reinit_error ,
172+ "log_to_driver" : log_to_driver ,
154173 "object_store_memory" : object_store_memory ,
155174 "_redis_password" : redis_password ,
156175 "_memory" : object_store_memory ,
0 commit comments