
    shS              
           S SK r S SKrS SKrS SKJr  S SKJr  S SKJrJ	r	J
r
  \
(       a  S SKJr  SS/r\ R                  " \5      rS\S	\S
\	S\S\4
S jr " S S5      rg)    N)ThreadPoolExecutor)Event)OptionalTextIOTYPE_CHECKING)Futuretail_logfileTailLogheaderfiledstfinishedinterval_secc                    [         R                  R                  U5      (       dR  UR                  5       (       a  g [        R
                  " U5        [         R                  R                  U5      (       d  MR  [        USS9 n UR                  5       nU(       a  UR                  U  U 35        O,UR                  5       (       a  O[        R
                  " U5        M[  S S S 5        g ! , (       d  f       g = f)Nreplace)errors)	ospathexistsis_settimesleepopenreadlinewrite)r   r   r   r   r   fplines          چ/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/torch/distributed/elastic/multiprocessing/tail_log.pyr	   r	      s     ggnnT""??

<  ggnnT""
 
d9	%;;=D		VHTF+,??$$ JJ|,  
&	%	%s   AC''
C5c                   z    \ rS rSrSr  SS\S\\\4   S\S\	\\\4      S\
4
S	 jjrSS jrSS jrS
\4S jrSrg)r
   2   a  
Tail the given log files.

The log files do not have to exist when the ``start()`` method is called. The tail-er will gracefully wait until
the log files are created by the producer and will tail the contents of the
log files until the ``stop()`` method is called.

.. warning:: ``TailLog`` will wait indefinitely for the log file to be created!

Each log file's line will be suffixed with a header of the form: ``[{name}{idx}]:``,
where the ``name`` is user-provided and ``idx`` is the index of the log file
in the ``log_files`` mapping. ``log_line_prefixes`` can be used to override the
header for each log file.

Usage:

::

 log_files = {0: "/tmp/0_stdout.log", 1: "/tmp/1_stdout.log"}
 tailer = TailLog("trainer", log_files, sys.stdout).start()
 # actually run the trainers to produce 0_stdout.log and 1_stdout.log
 run_trainers()
 tailer.stop()

 # once run_trainers() start writing the ##_stdout.log files
 # the tailer will print to sys.stdout:
 # >>> [trainer0]:log_line1
 # >>> [trainer1]:log_line1
 # >>> [trainer0]:log_line2
 # >>> [trainer0]:log_line3
 # >>> [trainer1]:log_line2

.. note:: Due to buffering log lines between files may not necessarily
          be printed out in order. You should configure your application's
          logger to suffix each log line with a proper timestamp.

Nname	log_filesr   log_line_prefixesr   c                 B   [        U5      nS U l        US:  a(  [        UU R                  R                   SU 3S9U l        Xl        X0l        X l        X@l        UR                  5        Vs0 s H  ow[        5       _M     snU l        / U l        XPl        SU l        g s  snf )Nr   _)max_workersthread_name_prefixF)len_threadpoolr   	__class____qualname___name_dst
_log_files_log_line_prefixeskeysr   _finished_events_futs_interval_sec_stopped)selfr!   r"   r   r#   r   n
local_ranks           r   __init__TailLog.__init__Y   s     	Nq51&*nn&A&A%B!D6#J D
 
	#"32;..2B3
2BJ2B3
 $&
)3
s   +Breturnc                    U R                   (       d  U $ U R                  R                  5        H  u  pSU R                   U S3nU R                  (       a  XR                  ;   a  U R                  U   nU R
                  R                  U R                   R                  [        UUU R                  U R                  U   U R                  S95        M     U $ )N[z]:)r   r   r   r   r   )r)   r.   itemsr,   r/   r2   appendsubmitr	   r-   r1   r3   )r5   r7   r   r   s       r   startTailLog.startt   s    K $ 5 5 7JZL3F&&:9P9P+P00<JJ  '' !		!22:>!%!3!3 ( 		 !8     c           	         U R                   R                  5        H  nUR                  5         M     [        U R                  5       H  u  p# UR                  5         M     U R                  (       a  U R                  R                  SS9  SU l        g ! [         aB  n[        R                  SU R                  UUR                  R                  U5         S nAM  S nAff = f)Nz$error in log tailor for %s%s. %s: %sT)wait)r1   valuesset	enumerater2   result	Exceptionloggererrorr,   r*   r+   r)   shutdownr4   )r5   r   r7   fes        r   stopTailLog.stop   s    --446HLLN 7 'tzz2MJ	
 3 %%4%0  :JJKK,, s   B
C7CCc                     U R                   $ )N)r4   )r5   s    r   stoppedTailLog.stopped   s    }}rB   )	r-   r1   r2   r3   r.   r/   r,   r4   r)   )Ng?)r:   r
   )r:   N)__name__
__module__r+   __firstlineno____doc__strdictintr   r   floatr8   r@   rO   boolrR   __static_attributes__ rB   r   r
   r
   2   sp    $V 7;! S> 	
 $DcN3 6(* rB   )loggingr   r   concurrent.futures.threadr   	threadingr   typingr   r   r   concurrent.futures._baser   __all__	getLoggerrT   rJ   rX   r[   r	   r
   r^   rB   r   <module>rf      sw     	  8  2 2 /9
%			8	$---!'-38-HM-0l lrB   