+
    –°³jÍ   ã                   óÌ   € ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	H
t
  ^ RIt]P                  ! ]4      tR tRR R llt ! R R4      tR#   ] d     L2i ; i)	é    N)ÚTextIOc                 óŠ  € \         P                  ! RR\         P                  \         P                  R7      p V  FF  pVw  r#p p \         P                   ! W#V4      pVP	                  R4       VP                  ^ 4       Vu # 	  \        R4      h  \         d*   pXP                  4        \        RT 24        Rp?K„  Rp?ii ; i)a}  
Find a free port and binds a temporary socket to it so that the port can be "reserved" until used.

.. note:: the returned socket must be closed before using the port,
          otherwise an ``address already in use`` error will happen.
          The socket should be held and closed as close to the
          consumer of the port as possible since otherwise, there
          is a greater chance of race-condition where a different
          process may see the port as being free and take it.

Returns: a socket bound to the reserved free port

Usage::

sock = find_free_port()
port = sock.getsockname()[1]
sock.close()
use_port(port)
Ú	localhostN)ÚhostÚportÚfamilyÚtypez Socket creation attempt failed: zFailed to create a socket)r   r   )
ÚsocketÚgetaddrinfoÚ	AF_UNSPECÚSOCK_STREAMÚbindÚlistenÚOSErrorÚcloseÚprintÚRuntimeError)ÚaddrsÚaddrr   r	   ÚprotoÚ_ÚsÚes           Úq/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/distributed/elastic/rendezvous/etcd_server.pyÚfind_free_portr      s±   € ô( ×ÒØ˜t¬F×,<Ñ,<Ä6×CUÑCUô€Eó ˆØ$(Ñ!ˆ�e˜Q ð	:Ü—’˜f¨EÓ2ˆAØ�F‰FÐ#Ô$Ø�H‰H�QŒKØŠHñ ô Ð2Ó
3Ð3øô ô 	:Ø�G‰GŒIÜÐ4°Q°CÐ8×9Ò9ûð	:ús   Á:BÂCÂB=Â=Cc                ó2   € V ^8„  d   QhR\         R,          /# ©é   Údata_dirN©Ústr)Úformats   "r   Ú__annotate__r#   C   s   € ÷ 4ñ 4¤C¨$¥Jñ 4ó    c                 ó  € V '       dK   V P                   ! 4       f8   \        P                  R4       V P                  ! 4        V P                  ! 4        V'       d1   \        P                  RV4       \
        P                  ! VRR7       R # R # )Nzstopping etcd serverzdeleting etcd data dir: %sT©Úignore_errors)ÚpollÚloggerÚinfoÚ	terminateÚwaitÚshutilÚrmtree)Ú
subprocessr   s   &&r   Ú	stop_etcdr0   C   sY   € ß�j—o’oÓ'Ò/Ü�‰Ð*Ô+Ø×ÒÔØ�ŠÔçÜ�‰Ð0°(Ô;Ü�Š�h¨d×3ñ r$   c                   óÜ   a € ] tR t^Nt o RtRV 3R lR lltV 3R lR ltV 3R lR ltV 3R	 lR
 ltV 3R lR lt	RV 3R lR llt
RV 3R lR lltR tRV 3R lR lltV 3R lR ltRtV tR# )Ú
EtcdServeraa  
.. note:: tested on etcd server v3.4.3.

Starts and stops a local standalone etcd server on a random free
port. Useful for single node, multi-worker launches or testing,
where a sidecar etcd server is more convenient than having to
separately setup an etcd server.

This class registers a termination handler to shutdown the etcd
subprocess on exit. This termination handler is NOT a substitute for
calling the ``stop()`` method.

The following fallback mechanism is used to find the etcd binary:

1. Uses env var TORCHELASTIC_ETCD_BINARY_PATH
2. Uses ``<this file root>/bin/etcd`` if one exists
3. Uses ``etcd`` from ``PATH``

Usage
::

 server = EtcdServer("/usr/bin/etcd", 2379, "/tmp/default.etcd")
 server.start()
 client = server.get_client()
 # use client
 server.stop()

Args:
    etcd_binary_path: path of etcd server binary (see above for fallback path)
Nc                ó.   <€ V ^8„  d   QhRS[ R,          /# r   r    )r"   Ú__classdict__s   "€r   r#   ÚEtcdServer.__annotate__n   s   ø€ ÷ 8ñ 8¡ t¥ñ 8r$   c                óÆ  € RV n         RV n        \        P                  P	                  \
        4      p\        P                  P                  VR4      p\        P                  P                  RV4      V n	        \        P                  P                  V P                  4      '       g   RV n	        V'       d   TM\        P                  ! RR7      V n        RV n        RV n        R# )	é   r   zbin/etcdÚTORCHELASTIC_ETCD_BINARY_PATHÚetcdÚtorchelastic_etcd_data)ÚprefixNéÿÿÿÿ)Ú_portÚ_hostÚosÚpathÚdirnameÚ__file__ÚjoinÚenvironÚgetÚ_etcd_binary_pathÚisfileÚtempfileÚmkdtempÚ_base_data_dirÚ	_etcd_cmdÚ
_etcd_proc)Úselfr   ÚrootÚdefault_etcd_bins   &&  r   Ú__init__ÚEtcdServer.__init__n   s¢   € ØˆŒ
Ø ˆŒ
ä�w‰w�‰œxÓ(ˆÜŸ7™7Ÿ<™<¨¨jÓ9ÐÜ!#§¡§¡Ø+Ð-=ó"
ˆÔô �w‰w�~‰~˜d×4Ñ4×5Ò5Ø%+ˆDÔ"÷ !‰H¤h×&6Ò&6Ð>VÔ&Wð 	Ôð ˆŒØ37ˆŽr$   c                ó4   <€ V ^8„  d   QhRS[ P                  /# ©r   Úreturn)r/   ÚPopen)r"   r4   s   "€r   r#   r5   €   s   ø€ ÷ #ñ #©*×*:Ñ*:ñ #r$   c                óT   € V P                   '       g   \        R 4      hV P                   # )z>No etcd server process started. Call etcd_server.start() first)rL   r   ©rM   s   &r   Ú_get_etcd_server_processÚ#EtcdServer._get_etcd_server_process€   s'   € Ø��ˆÜØPóð ð —?‘?Ð"r$   c                ó    <€ V ^8„  d   QhRS[ /# rS   ©Úint)r"   r4   s   "€r   r#   r5   ˆ   ó   ø€ ÷ ñ ™#ñ r$   c                ó   € V P                   # )z)Return the port the server is running on.)r=   rW   s   &r   Úget_portÚEtcdServer.get_portˆ   ó   € à�z‰zÐr$   c                ó    <€ V ^8„  d   QhRS[ /# rS   r    )r"   r4   s   "€r   r#   r5   Œ   r]   r$   c                ó   € V P                   # )z)Return the host the server is running on.)r>   rW   s   &r   Úget_hostÚEtcdServer.get_hostŒ   ra   r$   c                ó    <€ V ^8„  d   QhRS[ /# rS   r    )r"   r4   s   "€r   r#   r5   �   s   ø€ ÷ ,ñ ,™cñ ,r$   c                ó8   € V P                    RV P                   2# )z,Return the etcd server endpoint (host:port).Ú:)r>   r=   rW   s   &r   Úget_endpointÚEtcdServer.get_endpoint�   s   € à—*‘*�˜Q˜tŸz™z˜lÐ+Ð+r$   c                óN   <€ V ^8„  d   QhRS[ RS[ RS[ S[,          R,          RR/# )r   ÚtimeoutÚnum_retriesÚstderrNrT   )r\   r   )r"   r4   s   "€r   r#   r5   ”   sB   ø€ ÷ %Iñ %Iáð%Iñ ð%Iñ ‘f•˜tÕ#ð	%Ið
 
ñ%Ir$   c                ó°  € ^ p  \         P                  P                  V P                  \	        V4      4      p\         P
                  ! VRR7       V P                  WQV4      #   \         di   pT^,          p\        T P                  4       \        P                  RT4       YB8¼  d$   \        P                  ! T P                  RR7       h  Rp?KÍ  Rp?ii ; i)a‡  
Start the server, and waits for it to be ready. When this function returns the server is ready to take requests.

Args:
    timeout: time (in seconds) to wait for the server to be ready
        before giving up.
    num_retries: number of retries to start the server. Each retry
        will wait for max ``timeout`` before considering it as failed.
    stderr: the standard error file handle. Valid values are
        `subprocess.PIPE`, `subprocess.DEVNULL`, an existing file
        descriptor (a positive integer), an existing file object, and
        `None`.

Raises:
    TimeoutError: if the server is not ready within the specified timeout
T)Úexist_okz4Failed to start etcd server, got error: %s, retryingr&   N)r?   r@   rC   rJ   r!   ÚmakedirsÚ_startÚ	Exceptionr0   rL   r)   Úwarningr-   r.   ÚatexitÚregister)rM   rl   rm   rn   Úcurr_retriesr   r   s   &&&&   r   ÚstartÚEtcdServer.start”   sª   € ð, ˆØðÜŸ7™7Ÿ<™<¨×(;Ñ(;¼SÀÓ=NÓO�Ü—’˜H¨tÕ4Ø—{‘{ 8°fÓ=Ð=øÜô Ø Õ!�Ü˜$Ÿ/™/Ô*Ü—‘ØJÈAôð  Ô.Ü—M’M $×"5Ñ"5ÀTÕJØõ /ûðús   …AA" Á"CÁ-ACÃCc                óN   <€ V ^8„  d   QhRS[ RS[RS[S[,          R,          RR/# )r   r   rl   rn   NrT   )r!   r\   r   )r"   r4   s   "€r   r#   r5   »   s6   ø€ ÷ &ñ &Ùð&Ù&)ð&Ù8;¹f½ÀtÕ8Kð&à	ñ&r$   c                óX  € \        4       p\        4       pVP                  4       ^,          V n        VP                  4       ^,          p\        P                  ! RP                  V P                  RRVRRV P                   RV P                   2RRV P                   RV P                   2RRV P                   RV 2.
4      4      p\        P                  R	V4       VP                  4        VP                  4        \        P                  ! VR
VR7      V n        V P                  V4       R# )r7   Ú z--enable-v2z
--data-dirz--listen-client-urlszhttp://rh   z--advertise-client-urlsz--listen-peer-urlszStarting etcd server: [%s]T)Ú	close_fdsrn   N)r   Úgetsocknamer=   ÚshlexÚsplitrC   rF   r>   r)   r*   r   r/   rU   rL   Ú_wait_for_ready)rM   r   rl   rn   ÚsockÚ	sock_peerÚ	peer_portÚetcd_cmds   &&&&    r   rr   ÚEtcdServer._start»   s  € ô ÓˆÜ"Ó$ˆ	Ø×%Ñ%Ó'¨Õ*ˆŒ
Ø×)Ñ)Ó+¨AÕ.ˆ	ä—;’;Ø�H‰Hà×*Ñ*Ø!Ø ØØ*Ø˜dŸj™j˜\¨¨4¯:©:¨,Ð7Ø-Ø˜dŸj™j˜\¨¨4¯:©:¨,Ð7Ø(Ø˜dŸj™j˜\¨¨9¨+Ð6ðóó
ˆô" 	�‰Ð0°(Ô;à�
‰
ŒØ�‰ÔÜ$×*Ò*¨8¸tÈFÔSˆŒØ×Ñ˜WÖ%r$   c                ó^   € \         P                  ! V P                  V P                  R^
R7      # )zNReturn an etcd client object that can be used to make requests to this server.ú/v2©r   r   Úversion_prefixÚread_timeout)r9   ÚClientr>   r=   rW   s   &r   Ú
get_clientÚEtcdServer.get_clientÛ   s%   € ä�{Š{Ø—‘ $§*¡*¸UÐQSô
ð 	
r$   c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   rl   rT   Nr[   )r"   r4   s   "€r   r#   r5   á   s   ø€ ÷ Mñ M¡sð M°Dñ Mr$   c                ó  € \         P                  ! V P                   V P                  R ^R7      p\        P                  ! 4       V,           p\        P                  ! 4       V8  dl   V P                  4       P                  4       e)   V P                  4       P                  p\        RV 24      h \        P                  RVP                  4       R# \        R4      h  \         d    \        P                  ! ^4        K´  i ; i)rˆ   r‰   Nz*Etcd server process exited with the code: zetcd server ready. version: %sz.Timed out waiting for etcd server to be ready!)r9   rŒ   r>   r=   ÚtimerX   r(   Ú
returncoder   r)   r*   Úversionrs   ÚsleepÚTimeoutError)rM   rl   ÚclientÚmax_timeÚexitcodes   &&   r   r�   ÚEtcdServer._wait_for_readyá   sÌ   € Ü—’Ø—J‘J�< t§z¡zÀ%ÐVWô
ˆô —9’9“; Õ(ˆä�iŠi‹k˜HÔ$Ø×,Ñ,Ó.×3Ñ3Ó5ÒAà×8Ñ8Ó:×EÑE�Ü"Ø@ÀÀ
ÐKóð ðÜ—‘Ð<¸f¿n¹nÔMÙô ÐKÓLÐLøô ô Ü—
’
˜1—ðús   Â/ C Ã!DÄ Dc                ó   <€ V ^8„  d   QhRR/# )r   rT   N© )r"   r4   s   "€r   r#   r5   õ   s   ø€ ÷ 8ñ 8�dñ 8r$   c                óp   € \         P                  R4       \        V P                  V P                  4       R# )zGStop the server and cleans up auto generated resources (e.g. data dir).zEtcdServer stop method calledN)r)   r*   r0   rL   rJ   rW   s   &r   ÚstopÚEtcdServer.stopõ   s#   € ä�‰Ð3Ô4Ü�$—/‘/ 4×#6Ñ#6Ö7r$   )rJ   rF   rK   rL   r>   r=   ©N)é<   é   N)r    N)r    )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rP   rX   r_   rd   ri   rx   rr   r�   r�   r�   Ú__static_attributes__Ú__classdictcell__)r4   s   @r   r2   r2   N   so   ø‡ € ñ÷>8ò 8÷$#ð #÷ð ÷ð ÷,ð ,÷%Iò %I÷N&ò &ò@
÷Mò M÷(8ö 8r$   r2   rŸ   )ru   Úloggingr?   r   r-   r
   r/   rH   r‘   Útypingr   r9   ÚModuleNotFoundErrorÚ	getLoggerr¢   r)   r   r0   r2   r›   r$   r   Ú<module>r­      sk   ðó Û Û 	Û Û Û Û Û Û Ý ð	Ûð
 
×	Ò	˜8Ó	$€ò"4÷J4÷j8ó j8øðo ô 	Ùð	ús   ¬A ÁA#Á"A#