
    Vh                      .   U d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZmZmZ i aeeej&                  f   ed<   dded	ej&                  fd
Zddeded	dfdZded	dfdZ	 	 	 	 	 	 ddedededededee   dedee   dee   d	dfdZy)aS  
Module contains events processing mechanisms that are integrated with the standard python logging.

Example of usage:

::

  from torch.distributed.elastic import events

  event = events.Event(
      name="test_event", source=events.EventSource.WORKER, metadata={...}
  )
  events.get_logging_handler(destination="console").info(event)

    N)Optional)get_logging_handler   )EventEventMetadataValueEventSource	NodeState	RdzvEvent_events_loggersdestinationreturnc                 
   | t         vrst        j                  d|        }|j                  t        j
                  j                  dd             d|_        t        |       }|j                  |       |t         | <   t         |    S )a  
    Construct python logger based on the destination type or extends if provided.

    Available destination could be found in ``handlers.py`` file.
    The constructed logger does not propagate messages to the upper level loggers,
    e.g. root logger. This makes sure that a single event can be processed once.

    Args:
        destination: The string representation of the event handler.
            Available handlers found in ``handlers`` module
    ztorchelastic-events-LOGLEVELINFOF)
r   logging	getLoggersetLevelosenvironget	propagater   
addHandler)r   _events_loggerlogging_handlers      Y/home/dcms/DCMS/lib/python3.12/site-packages/torch/distributed/elastic/events/__init__.py_get_or_create_loggerr   .   sx     /) **-A++OP

z6 BC#( -k:!!/2 (6$;''    eventc                 T    t        |      j                  | j                                y )Nr   info	serialize)r   r   s     r   recordr#   K   s    +&++EOO,=>r   c                 T    t        d      j                  | j                                y )Ndynamic_rendezvousr    )r   s    r   record_rdzv_eventr&   O   s    ./44U__5FGr   run_idmessage
node_statenamehostnamepidmaster_endpointlocal_idrankc	                    t        t        d      t        j                        ry|st	        j
                         }|st        j                         }t        j                         }	d}
t        |	      dkD  r<|	d   }t        j                  j                  |j                        }
|s|j                  }~	|t        j                   k(  rt#        j$                         }nd}t'        |
 d| | ||||||||
      }t)        |       y)a  
    Initialize rendezvous event object and record its operations.

    Args:
        run_id (str): The run id of the rendezvous.
        message (str): The message describing the event.
        node_state (NodeState): The state of the node (INIT, RUNNING, SUCCEEDED, FAILED).
        name (str): Event name. (E.g. Current action being performed).
        hostname (str): Hostname of the node.
        pid (Optional[int]): The process id of the node.
        master_endpoint (str): The master endpoint for the rendezvous store, if known.
        local_id (Optional[int]):  The local_id of the node, if defined in dynamic_rendezvous.py
        rank (Optional[int]): The rank of the node, if known.
    Returns:
        None
    Example:
        >>> # See DynamicRendezvousHandler class
        >>> def _record(
        ...     self,
        ...     message: str,
        ...     node_state: NodeState = NodeState.RUNNING,
        ...     rank: Optional[int] = None,
        ... ) -> None:
        ...     construct_and_record_rdzv_event(
        ...         name=f"{self.__class__.__name__}.{get_method_name()}",
        ...         run_id=self._settings.run_id,
        ...         message=message,
        ...         node_state=node_state,
        ...         hostname=self._this_node.addr,
        ...         pid=self._this_node.pid,
        ...         local_id=self._this_node.local_id,
        ...         rank=rank,
        ...     )
    r%   Nno_filer    :)
r*   r'   r(   r+   r,   r)   r-   r/   r.   error_trace)
isinstancer   r   NullHandlersocketgetfqdnr   getpidinspectstacklenpathbasenamefilenamefunctionr	   FAILED	traceback
format_excr
   r&   )r'   r(   r)   r*   r+   r,   r-   r.   r/   	callstackr?   stack_depth_1r4   r   s                 r   construct_and_record_rdzv_eventrF   S   s    \ %&:;W=P=PQ >>#iik IH
9~!!77##M$:$:; ))D
 	 Y%%%**, z4&!'E er   )null)r2   r2   Nr2   NN)__doc__r:   r   r   r7   rB   typingr   )torch.distributed.elastic.events.handlersr   apir   r   r   r	   r
   r   dictstrLogger__annotations__r   r#   r&   intrF    r   r   <module>rR      s      	    I  .0c7>>)* /(s ( (:?% ?c ?t ?HY H4 H "ZZZ Z 	Z
 Z 
#Z Z smZ 3-Z 
Zr   