Ë
    :vžjÝ  ã                  óf   — d Z ddlmZ ddlZddlZddlmZmZm	Z	m
Z
mZmZ ddlmZ  G d„ de«      Zy)zÊA basic kernel monitor with autorestarting.

This watches a kernel's state using KernelManager.is_alive and auto
restarts the kernel if it dies.

It is an incomplete base class, and must be subclassed.
é    )ÚannotationsN)ÚBoolÚDictÚFloatÚInstanceÚIntegerÚdefault)ÚLoggingConfigurablec                  ó4  — e Zd ZdZ ed«      Z eddd¬«      Z eddd¬«      Z	 ed	dd
¬«      Z
 eddd¬«      Z eddd¬«      Z ed«      Z ed«      Z ed«      Z e«       Z ed«      dd„«       Z e«       Zdd„Zdd„Zdd„Zddd„Zddd„Zdd„Zdd„Zy)ÚKernelRestarterz!Monitor and autorestart a kernel.zjupyter_client.KernelManagerFTz�Whether to include every poll event in debugging output.

        Has to be set explicitly, because there will be *a lot* of output.
        )ÚconfigÚhelpg      @z%Kernel heartbeat interval in seconds.g      $@zOThe time in seconds to consider the kernel to have completed a stable start up.é   zJThe number of consecutive autorestarts before the kernel is presumed dead.zNWhether to choose new random ports when restarting before the kernel is alive.r   Ú
_last_deadc                ó*   — t        j                   «       S )N)Útime©Úselfs    úi/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/jupyter_client/restarter.pyÚ_default_last_deadz"KernelRestarter._default_last_dead:   s   € ä�y‰y‹{Ðó    c                ó   — g g dœS )N)ÚrestartÚdead© r   s    r   Ú_callbacks_defaultz"KernelRestarter._callbacks_default@   s   € Ø rÑ*Ð*r   c                ó   — d}t        |«      ‚)z Start the polling of the kernel.ú!Must be implemented in a subclass©ÚNotImplementedError©r   Úmsgs     r   ÚstartzKernelRestarter.startC   ó   € à1ˆÜ! #Ó&Ð&r   c                ó   — d}t        |«      ‚)zStop the kernel polling.r   r   r!   s     r   ÚstopzKernelRestarter.stopH   r$   r   c                ó@   — | j                   |   j                  |«       y)zçregister a callback to fire on a particular event

        Possible values for event:

          'restart' (default): kernel has died, and will be restarted.
          'dead': restart has failed, kernel will be left dead.

        N)Ú	callbacksÚappend©r   ÚfÚevents      r   Úadd_callbackzKernelRestarter.add_callbackM   s   € ð 	�‰�uÑ×$Ñ$ QÕ'r   c                ó`   — 	 | j                   |   j                  |«       y# t        $ r Y yw xY w)zéunregister a callback to fire on a particular event

        Possible values for event:

          'restart' (default): kernel has died, and will be restarted.
          'dead': restart has failed, kernel will be left dead.

        N)r(   ÚremoveÚ
ValueErrorr*   s      r   Úremove_callbackzKernelRestarter.remove_callbackX   s0   € ð	Ø�N‰N˜5Ñ!×(Ñ(¨Õ+øÜò 	Ùð	ús   ‚! ¡	-¬-c                ó˜   — | j                   |   D ]
  }	  |«        Œ y# t        $ r" | j                  j                  d||d¬«       Y Œ8w xY w)z)fire our callbacks for a particular eventz&KernelRestarter: %s callback %r failedT)Úexc_infoN)r(   Ú	ExceptionÚlogÚerror)r   r,   Úcallbacks      r   Ú_fire_callbackszKernelRestarter._fire_callbacksf   sQ   € àŸ™ uÔ-ˆHðÙ•
ñ .øô ò Ø—‘—‘Ø<ØØØ!ð	 ö ðús   ”ž(A	ÁA	c                ó¦  — | j                   r| j                  j                  d«       | j                  j                  r| j                  j                  d«       y t	        j                  «       }| j                  j                  «       �s|| _        | j                  r| xj                  dz  c_        nd| _        | j                  | j                  kD  rK| j                  j                  d«       | j                  d«       d| _        d| _        | j                  «        y | j                  xr | j                  }| j                  j                  d| j                  | j                  |rd	nd
«       | j                  d«       | j                  j!                  d|¬«       d| _        y | j"                  }| j                  j$                  r&| j                  j$                  j'                  |¬«      }| j                  r|| j                  z
  |k\  rd| _        | j                  r6|| j                  z
  |k\  r#| j                  j                  d«       d| _        y y y )NzPolling kernel...zKernel shutdown in progress...é   zKernelRestarter: restart failedr   Fr   z;KernelRestarter: restarting kernel (%i/%i), %s random portsÚnewÚkeepr   T)ÚnowÚnewports)Úrecommendedz-KernelRestarter: restart apparently succeeded)Údebugr5   Úkernel_managerÚshutting_downr   Úis_aliver   Ú_restartingÚ_restart_countÚrestart_limitÚwarningr8   r&   Úrandom_ports_until_aliveÚ_initial_startupÚinfoÚrestart_kernelÚstable_start_timeÚprovisionerÚget_stable_start_time)r   r=   r>   rL   s       r   ÚpollzKernelRestarter.polls   sç  € Ø�:Š:Ø�H‰H�N‰NÐ.Ô/Ø×Ñ×,Ò,Ø�H‰H�N‰NÐ;Ô<ØÜ�i‰i‹kˆØ×"Ñ"×+Ñ+Õ-Ø!ˆDŒOØ×ÒØ×#Ò# qÑ(Ö#à&'�Ô#à×"Ñ" T×%7Ñ%7Ò7Ø—‘× Ñ Ð!BÔCØ×$Ñ$ VÔ,Ø#(�Ô Ø&'�Ô#Ø—	‘	•à×8Ñ8ÒR¸T×=RÑ=R�Ø—‘—‘ØQØ×'Ñ'Ø×&Ñ&Ù%‘E¨6ô	ð ×$Ñ$ YÔ/Ø×#Ñ#×2Ñ2°tÀhÐ2ÔOØ#'�Õ ð !%× 6Ñ 6ÐØ×"Ñ"×.Ò.Ø$(×$7Ñ$7×$CÑ$C×$YÑ$YØ 1ð %Zó %Ð!ð ×$Ò$¨¨t¯©Ñ)>ÐBSÒ)SØ(-�Ô%Ø×Ò C¨$¯/©/Ñ$9Ð=NÒ$NØ—‘—‘ÐNÔOØ#(�Õ ð %OÐr   N)ÚreturnÚfloat)rP   zdict[str, list])rP   ÚNone)r   )r+   zt.Callable[..., t.Any]r,   ÚstrrP   rR   )r,   zt.AnyrP   rR   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rA   r   r@   r   Útime_to_deadrL   r   rF   rH   rD   rE   rI   r   r	   r   r   r(   r   r#   r&   r-   r1   r8   rO   r   r   r   r   r      sÝ   „ Ù+áÐ<Ó=€NáØØðô€Eñ ˜ TÐ0[Ô\€LáØØØbôÐñ Ø	ØØ]ô€Mñ  $ØØØaô Ðñ
 �u“+€KÙ˜Q“Z€NÙ˜D“zÐÙ“€Jáˆ\Óòó ðñ “€Ió+ó'ó
'ô
	(ôóô0)r   r   )rW   Ú
__future__r   r   ÚtypingÚtÚ	traitletsr   r   r   r   r   r	   Útraitlets.config.configurabler
   r   r   r   r   Ú<module>r^      s-   ðñõ #ã Û ç C× CÝ =ôO)Ð)õ O)r   