
    [Th#                         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	  S SK
Jr  S SKJr  / SQr\" \5      rSrSrS	r      SS
\S\S\S\S\S\S\\   4S jjrS rS rS\R                  4S jrg)    N)closing)Optional)
get_logger)barrier)create_c10d_storeget_free_portget_socket_with_portzAddress already in usezSocket Timeoutz_tcp_store/num_members	is_serverserver_addrserver_port
world_sizetimeoutwait_for_workers	use_libuvc           
         Ub  [         R                  S5        [        R                  R	                  SS5      S:H  nUS:X  a  US:  a  [        SU SU 35      eUS:w  a  [         R                  SU5        US:X  a  UOSn US:w  a  Un	O
[        5       n	[         R                  S	UU	UU UU5         [        R                  " UU	UU [        R                  " US
9UUS9n
U(       a
  [        XUS9  [         R                  S5        U
$ ! [         aS  n[        U5      [        :X  a:  X:  a"  [         R                  SU	UU5        US-  n S nAO[        SU SU	 S35      Uee S nAff = fM  )Nzargument use_libuv is deprecated and ignored. Set USE_LIBUV environment variable to "0" to disable libuv, or "1" to enable it. If the env var is not set, libuv will be used by default.	USE_LIBUV1   zCserver_port must be specified when world_size > 1, got server_port=z, world_size=z+sever_port: %s, specified, ignoring retriesziCreating c10d store on %s:%s
  world_size  : %s
  is_server   : %s
  timeout(sec): %s
  use_libuv   : %s
)seconds)	host_nameportr   	is_masterr   r   r   )r   zSuccessfully created c10d storez)port: %s already in use, attempt: [%s/%s]zon z, port: z already in use)loggerwarningosenvironget
ValueErrorinfor   distTCPStoredatetime	timedelta_check_full_rankRuntimeErrorstr_ADDRESS_IN_USE)r
   r   r   r   r   r   retriesr   attemptr   storees               c/var/www/auris/envauris/lib/python3.13/site-packages/torch/distributed/elastic/utils/distributed.pyr   r      s    9	
 

{C0C7IbZ!^QR]Q^^klvkwx
 	
 bA;O %*gG
"D ?D#
 	
#	MM%%# **7;!1#E   GDKK9:L 	 1v($NNC	 qLG&k](4&H )	G s   /AD 
E 5EEE c                      [        X[        US9  g ! [         a)  n[        U5      [        :X  a  [        SU S35      Uee S nAff = f)N)
key_prefixbarrier_timeoutztimed out waiting for all z members to join)r   _TCP_STORE_INITr&   r'   _SOCKET_TIMEOUTTimeoutError)r+   r   r   r,   s       r-   r%   r%   v   sQ    owW q6_$,ZL8HI s    
A$A  Ac                      [        5       n [        U 5         U R                  5       S   sSSS5        $ ! , (       d  f       g= f)a  
Returns an unused port on localhost.

This function finds an unused port on localhost by opening to socket to bind
to a port and then closing it.

Returns:
    int: an unused port on localhost

Example:
    >>> # xdoctest: +SKIP("Nondeterministic")
    >>> get_free_port()
    63976

.. note::
    The port returned by :func:`get_free_port` is not reserved and may be
    taken by another process after this function returns.
r   N)r	   r   getsockname)socks    r-   r   r      s.    &  !D	!!$ 
s	   3
Areturnc                     [         R                  " SS[         R                  [         R                  S9n U  HF  nUu  p#n  n[         R                   " X#U5      n UR	                  S5        UR                  S5        Us  $    [        S5      e! [         a/  nUR                  5         [        R                  SUS9   SnAM  SnAff = f)	a  
Returns a free port on localhost that is "reserved" by binding a temporary
socket on it. Close the socket before passing the port to the entity
that requires it. Usage example

::

sock = _get_socket_with_port()
with closing(sock):
    port = sock.getsockname()[1]
    sock.close()
    # there is still a race-condition that some other process
    # may grab this port before func() runs
    func(port)
	localhostN)hostr   familytype)r9   r   r   zSocket creation attempt failed.)exc_infozFailed to create a socket)socketgetaddrinfo	AF_UNSPECSOCK_STREAMbindlistenOSErrorcloser   r   r&   )addrsaddrr;   r<   proto_sr,   s           r-   r	   r	      s    " tF,<,<6CUCUE $(!eQMM&.	JFF#$HHQKH  2
33  	JGGINN<qNI	Js   #B
C$B??C)r   r   iX  T   N)r#   r   r>   
contextlibr   typingr   torch.distributeddistributedr!   'torch.distributed.elastic.utils.loggingr   %torch.distributed.elastic.utils.storer   __all____name__r   r(   r2   r1   boolr'   intfloatr   r%   r   r	        r-   <module>rY      s     	      > 9 I	H	*"* ! $UUU U 	U
 U U ~Up	%04fmm 4rX   