
    <h                    f    S r SSKJr  SSKrSSKrSSKJrJrJ	r	J
r
JrJr  SSKJr   " S S\5      rg)zA 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                  2   \ rS rSrSr\" S5      r\" SSSS9r\	" SSS	S9r
\	" S
SSS9r\" SSSS9r\" SSSS9r\" S5      r\" S5      r\" S5      r\	" 5       r\" S5      SS j5       r\" 5       rSS jrSS jrSS jrSSS jjrSSS jjrS S jrSS jrSrg)!KernelRestarter   z!Monitor and autorestart a kernel.zjupyter_client.KernelManagerFTzWhether 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                ,    [         R                   " 5       $ )N)timeselfs    kC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\jupyter_client/restarter.py_default_last_dead"KernelRestarter._default_last_dead9   s    yy{    c                    / / S.$ )N)restartdead r   s    r   _callbacks_default"KernelRestarter._callbacks_default?   s    r**r   c                    Sn[        U5      e)z Start the polling of the kernel.!Must be implemented in a subclassNotImplementedErrorr   msgs     r   startKernelRestarter.startB       1!#&&r   c                    Sn[        U5      e)zStop the kernel polling.r!   r"   r$   s     r   stopKernelRestarter.stopG   r(   r   c                @    U R                   U   R                  U5        g)zregister 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_callbackKernelRestarter.add_callbackL   s     	u$$Q'r   c                b     U R                   U   R                  U5        g! [         a     gf = f)zunregister 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_callbackKernelRestarter.remove_callbackW   s0    	NN5!((+ 		s   ! 
..c           	         U R                   U    H  n U" 5         M     g! [         a     U R                  R                  SUUSS9   M9  f = f)z)fire our callbacks for a particular eventz&KernelRestarter: %s callback %r failedT)exc_infoN)r-   	Exceptionlogerror)r   r1   callbacks      r   _fire_callbacksKernelRestarter._fire_callbackse   sQ    u-H
 .  <!	  s    &A
	A
c                   U R                   (       a  U R                  R                  S5        U R                  R                  (       a  U R                  R                  S5        g [        R                  " 5       nU R                  R                  5       (       Gd&  Xl        U R                  (       a  U =R                  S-  sl        OSU l        U R                  U R                  :  aK  U R                  R                  S5        U R                  S5        SU l        SU l        U R                  5         g U R                  =(       a    U R                  nU R                  R                  SU R                  U R                  U(       a  S	OS
5        U R                  S5        U R                  R!                  SUS9  SU l        g U R"                  nU R                  R$                  (       a#  U R                  R$                  R'                  US9nU R                  (       a  XR                  -
  U:  a  SU l        U R                  (       a6  XR                  -
  U:  a#  U R                  R                  S5        SU l        g g g )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)debugr<   kernel_managershutting_downr   is_aliver   _restarting_restart_countrestart_limitwarningr?   r*   random_ports_until_alive_initial_startupinforestart_kernelstable_start_timeprovisionerget_stable_start_time)r   rE   rF   rT   s       r   pollKernelRestarter.pollr   s   ::HHNN./,,HHNN;<iik""++--!O##q(#&'#""T%7%77  !BC$$V,#( &'#		88RT=R=RQ''&&%E6	 $$Y/##22th2O#'  !% 6 6""..$($7$7$C$C$Y$Y 1 %Z %! $$)>BS)S(-%C//$9=N$NNO#(  %Or   )rQ   r   rM   rL   N)returnfloat)rY   zdict[str, list])rY   None)r   )r0   zt.Callable[..., t.Any]r1   strrY   r[   )r1   zt.AnyrY   r[   )__name__
__module____qualname____firstlineno____doc__r   rI   r   rH   r   time_to_deadrT   r   rN   rP   rL   rM   rQ   r   r	   r   r   r-   r   r&   r*   r2   r7   r?   rW   __static_attributes__r   r   r   r   r      s    +<=NE T0[\Lb 	]M  $a 
 u+KQZNDzJ\  I+'
'
	(0)r   r   )ra   
__future__r   r   typingt	traitletsr   r   r   r   r   r	   traitlets.config.configurabler
   r   r   r   r   <module>ri      s-    #   C C =O)) O)r   