
    Mhrv                        d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZmZmZmZmZmZmZmZmZm Z m!Z! ddl"m#Z# d	d
l$m%Z% d	dl&m'Z' d	dl(m)Z) d	dl*m+Z+ d	dl,m-Z- d	dl.m/Z/ d	dl0m1Z1 d	dl0m2Z3  G d de          Z4 ej5        dej6        dej        f                   Z7dej8        eef         fdZ9de7de7fdZ: G d de-          Z; G d de;          Z< e/j=        e;           	 d'd!e>d"e?d#ej        dej@        e;e)f         fd$ZA	 d'd!e>d"e?d#ej        dej@        e<e'f         fd%ZBed#ej        dejC        e+         fd&            ZDdS )(z%Base class to manage a running kernel    N)Future)contextmanager)Enum)run_sync)AnyBoolDictDottedObjectNameFloatInstanceTypeUnicodedefaultobserveobserve_compat)import_item   )
kernelspec)AsyncKernelClient)BlockingKernelClient)KernelClient)ConnectionFileMixin)KernelManagerABC)KernelProvisionerBase)KernelProvisionerFactoryc                   "    e Zd ZdZdZdZdZdZdS )_ShutdownStatusz

    This is so far used only for testing in order to track the internal state of
    the shutdown logic, and verifying which path is taken for which
    missbehavior.

    NShutdownRequestSigtermRequestSigkillRequest)__name__
__module____qualname____doc__Unsetr   r   r         V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jupyter_client/manager.pyr   r   -   s.          E'O%N%NNNr'   r   F.)boundreturnc                      	 t          j                     t                      S # t          $ r t	                      cY S w xY w)z Get an appropriate Future object)asyncioget_running_loopr   RuntimeErrorCFuturer&   r'   r(   _get_futurer1   ?   sJ     """xx   yys    # >>methodc           
           t           j        t          j                   dt           j        dt           j        dt           j        dt           j        f fd                        }t          j        t          |          S )zSets the kernel to a pending state by
    creating a fresh Future for the KernelManager's `ready`
    attribute. Once the method is finished, set the Future's results.
    selfargskwargsr+   c                   K   | j         s| j        st                      | _        	  | g|R i | d{V }t          j        d           d{V  | j        r| j                            d           |S # t          $ rR}| j                            |           | j	        
                    | j        
                                           |d}~ww xY w)z)Create a future for the decorated method.Ng{Gz?)_attempted_start_readyr1   r-   sleepowns_kernel
set_result	Exceptionset_exceptionlog	exception)r4   r5   r6   outer2   s        r(   wrapperz!in_pending_state.<locals>.wrapperO   s        	( 	(%--DK	t5d555f55555555C-%%%%%%%%% -&&t,,,J 	 	 	K%%a(((Ht{4466777G	s   AA5 5
C?ACC)tno_type_check	functoolswrapsr   castr)   )r2   rC   s   ` r(   in_pending_staterI   I   s|     __VAE !% 15 QU       _" 6!Wr'   c            	       	    e Zd ZU dZej        ej        eef                  e	d<   dej
        dej
        ddf fdZ ed          Zee	d	<    eej                  Zee	d
<    ed
          dej        fd            Z ed          Zee	d<    ee          Zee	d<    ed          defd            Z ed          dej        eef         ddfd            Z edd          Zej        eef         e	d<   dZ ej        e!         e	d<    ee"j#                  Z$ee	d<    ed          de"j#        fd            Z% ed          e&dej        eef         ddfd                        Z' e(ddd          Z)e(e	d<    ee"j*                  Z+ej        eef         e	d<    ed          dej        eef         ddfd            Z,dZ-ej        e"j.                 e	d <   e/dej        e"j.                 fd!            Z0 eddd"          Z1ee	d#<    ed#          de2fd$            Z3e/dej        eef         fd%            Z4e/de2fd&            Z5 ed          Z6ej        d'         e	d(<    e
            Z7e
e	d)<    e
            Z8e
e	d*<    eddd+          Z9ee	d,<   dZ:e2e	d-<   dVd.Z;dVd/Z<dVd0Z=dWd2ej>        d3eddfd4Z?dWd2ej>        d3eddfd5Z@dej
        deAfd6ZBd7ej        eef         ddfd8ZCdXd9ej        ejD        e                  dejD        e         fd:ZEd;ejD        e         d<ej
        ddfd=ZF eGeF          ZHdVd>ZIdVd?ZJd<ej
        dejK        ejD        e         ej        eej
        f         f         fd@ZL eGeL          ZMd<ej
        ddfdAZN eGeN          ZOePd<ej
        ddfdB            ZQ eGeQ          ZRdYd1e2ddfdCZS eGeS          ZT	 	 	 dZdEej        eU         dFeUd1e2ddfdGZV eGeV          ZWdYd1e2ddfdHZX eGeX          ZYePd[dIe2d1e2ddfdJ            ZZ eGeZ          Z[	 d[dIe2dKe2d<ej
        ddfdLZ\ eGe\          Z]e/de2fdM            Z^e/de2fdN            Z_dYd1e2ddfdOZ` eGe`          ZadYd1e2ddfdPZb eGeb          ZcdVdQZd eGed          ZedRefddfdSZg eGeg          Zhde2fdTZi eGei          Zjd\dFeUddfdUZk xZlS )]KernelManagerzgManages a single kernel in a subprocess on this host.

    This version starts kernels with Popen.
    r9   r5   r6   r+   Nc                     |rt          j        dt          d           |                    dd          | _         t                      j        di | t          j        | _	        d| _
        d| _        dS )	zInitialize a kernel manager.zPassing positional only arguments to `KernelManager.__init__` is deprecated since jupyter_client 8.6, and will become an error on future versions. Positional  arguments have been ignored since jupyter_client 7.0   )
stacklevelr;   TFNr&   )warningswarnDeprecationWarningpop_owns_kernelsuper__init__r   r%   _shutdown_statusr8   r9   )r4   r5   r6   	__class__s      r(   rU   zKernelManager.__init__m   s     	MH #    #JJ}d;;""6""" / 5 %r'   F_created_contextcontextc                 6    d| _         t          j                    S NT)rX   zmqContextr4   s    r(   _context_defaultzKernelManager._context_default   s     ${}}r'   z,jupyter_client.blocking.BlockingKernelClientclient_classklassclient_factoryc                 *    t          | j                  S N)r   r`   r^   s    r(   _client_factory_defaultz%KernelManager._client_factory_default   s    4,---r'   changec                 T    t          t          |d                             | _        d S )Nnew)r   strrc   r4   rg   s     r(   _client_class_changedz#KernelManager._client_class_changed   s$    )#fUm*<*<==r'   T)
allow_none	kernel_idprovisionerkernel_spec_managerc                 6    t          j        | j                  S )N)data_dir)r   KernelSpecManagerrr   r^   s    r(   _kernel_spec_manager_defaultz*KernelManager._kernel_spec_manager_default   s    +T]CCCCr'   c                     d | _         d S re   )_kernel_specrk   s     r(   _kernel_spec_manager_changedz*KernelManager._kernel_spec_manager_changed   s     !r'         @a  Time to wait for a kernel to terminate before killing it, in seconds. When a shutdown request is initiated, the kernel will be immediately sent an interrupt (SIGINT), followedby a shutdown_request message, after 1/2 of `shutdown_wait_time`it will be sent a terminate (SIGTERM) request, and finally at the end of `shutdown_wait_time` will be killed (SIGKILL). terminate and kill may be equivalent on windows.  Note that this value can beoverridden by the in-use kernel provisioner since shutdown times mayvary by provisioned environment.)confighelpshutdown_wait_timekernel_namec                 R    d | _         |d         dk    rt          j        | _        d S d S )Nri   python)rv   r   NATIVE_KERNEL_NAMEr|   rk   s     r(   _kernel_name_changedz"KernelManager._kernel_name_changed   s2     %=H$$)<D %$r'   rv   c                 |    | j         /| j        dk    r$| j                            | j                  | _         | j         S )N )rv   r|   rp   get_kernel_specr^   s    r(   kernel_speczKernelManager.kernel_spec   s=    $)9R)?)? $ 8 H HIY Z ZD  r'   zQTrue if the MultiKernelManager should cache ports for this KernelManager instancecache_portsc                     | j         dk    S )Ntcp)	transportr^   s    r(   _default_cache_portsz"KernelManager._default_cache_ports   s    ~&&r'   c                 D    | j         st                      | _         | j         S )zMA future that resolves when the kernel process has started for the first time)r9   r1   r^   s    r(   readyzKernelManager.ready   s!     { 	(%--DK{r'   c                     | j         dv S )N>   r~   python2python3r|   r^   s    r(   	ipykernelzKernelManager.ipykernel   s    #CCCr'   zDict[str, Any]_launch_args_control_socket
_restarterz,Should we autorestart the kernel if it dies.autorestartshutting_downc                 V    |                                   |                                  d S re   )_close_control_socketcleanup_connection_filer^   s    r(   __del__zKernelManager.__del__   s,    ""$$$$$&&&&&r'   c                     dS )zStart the kernel restarter.Nr&   r^   s    r(   start_restarterzKernelManager.start_restarter       r'   c                     dS )zStop the kernel restarter.Nr&   r^   s    r(   stop_restarterzKernelManager.stop_restarter   r   r'   restartcallbackeventc                 N    | j         dS | j                             ||           dS )z;Register a callback to be called when a kernel is restartedN)r   add_callbackr4   r   r   s      r(   add_restart_callbackz"KernelManager.add_restart_callback   s-    ?"F$$Xu55555r'   c                 N    | j         dS | j                             ||           dS )z=Unregister a callback to be called when a kernel is restartedN)r   remove_callbackr   s      r(   remove_restart_callbackz%KernelManager.remove_restart_callback   s-    ?"F''%88888r'   c                     i }|                     |                     d                     |                     | j        | d           |                     |            | j        di |S )z3Create a client configured to connect to our kernelT)session)connection_fileparentr&   )updateget_connection_infor   rc   )r4   r6   kws      r(   clientzKernelManager.client  s    
		$**4*88999
		#'#7 	
 	
 	
 			&"t"((R(((r'   envc                    t          | j        t                    rKd| j        v rDt          | j        d         t                    r&| j        d                             |           dS dS dS dS )a  
        Allow to update the environment of a kernel manager.

        This will take effect only after kernel restart when the new env is
        passed to the new kernel.

        This is useful as some of the information of the current kernel reflect
        the state of the session that started it, and those session information
        (like the attach file path, or name), are mutable.

        .. version-added: 8.5
        r   N)
isinstancer   dictr   )r4   r   s     r(   
update_envzKernelManager.update_env  s{     t($//	1***4,U3T:: + e$++C00000	1 	1****r'   extra_argumentsc                 H   |pg }| j         J | j         j        |z   }|rD|d         ddt          j        d         z  dt          j        dd         z  hv rt          j        |d<   t
          j                            | j                  t          j	        d| j         r| j         j
        d<   t          | j        t                    sJ                     | j                   t          j        d	          d
t"          j        dt"          j        ffdfd|D             S )z/Replace templated args (e.g. {connection_file})Nr   r~   zpython%izpython%i.%irM   )r   prefixresource_dirz\{([A-Za-z0-9_]+)\}matchr+   c                 z                         |                     d          |                                           S )z9Get the key out of ns if it's there, otherwise no change.r   )getgroup)r   nss    r(   from_nsz0KernelManager.format_kernel_cmd.<locals>.from_nsT  s)    66%++a..%++--888r'   c                 <    g | ]}                     |          S r&   )sub).0argr   pats     r(   
<listcomp>z3KernelManager.format_kernel_cmd.<locals>.<listcomp>X  s'    555#%%555r'   )r   argvsysversion_info
executableospathrealpathr   r   r   r   r   r   r   recompilerD   r   )r4   r   cmdr   r   r   s      @@@r(   format_kernel_cmdzKernelManager.format_kernel_cmd/  sR   )/R+++#o5 	$3q6)!,,C,RaR00
 
 
 ^CF  "w//0DEEj"
 "

  	?!%!1!>B~$+T22222
		$#$$$j/00	915 	9QU 	9 	9 	9 	9 	9 	9 655555555r'   
kernel_cmdr   c                    K   | j         J  | j         j        |fi | d{V }| j         j        sJ |                     |           dS )zactually launch the kernel

        override in a subclass to launch kernel subprocesses differently
        Note that provisioners can now be used to customize kernel environments
        and
        N)ro   launch_kernelhas_process_reconcile_connection_info)r4   r   r   connection_infos       r(   _async_launch_kernelz"KernelManager._async_launch_kernelZ  st       +++ > 0 >z P PR P PPPPPPP++++ 	''88888r'   c                 d    | j         (|                     d          | _         d| j         _        d S d S )Ncontrold   )r   _create_connected_socketlingerr^   s    r(   _connect_control_socketz%KernelManager._connect_control_socketl  s:    '#'#@#@#K#KD *-D ''' ('r'   c                 X    | j         d S | j                                          d | _         d S re   )r   closer^   s    r(   r   z#KernelManager._close_control_socketq  s3    'F""$$$#r'   c                   K   d| _         | j        p3|                    dt          t	          j                                        | _        |                                | _        | j        ?t          j
        | j                                      | j        | j        |           | _         | j        j        di | d{V }|                    d          }||fS )a{  Prepares a kernel for startup in a separate process.

        If random ports (port=0) are being used, this method must be called
        before the channels are created.

        Parameters
        ----------
        `**kw` : optional
             keyword arguments that are passed down to build the kernel_cmd
             and launching the kernel (e.g. Popen kwargs).
        Frn   N)r   r   r&   )r   rn   rR   rj   uuiduuid4copyr   ro   KPFinstancer   create_provisioner_instancer   
pre_launchr4   r   r   s      r(   _async_pre_start_kernelz%KernelManager._async_pre_start_kernelw  s       #Q266+s4:<<?P?P+Q+Q GGII#"|4;???[[   \    D
 /4#.4444444444VVE]]
2~r'   c                    K   |                                   |                                  | j        J  | j        j        di | d{V  dS )zPerforms any post startup tasks relative to the kernel.

        Parameters
        ----------
        `**kw` : optional
             keyword arguments that were used in the kernel process's launch.
        Nr&   )r   r   ro   post_launch)r4   r   s     r(   _async_post_start_kernelz&KernelManager._async_post_start_kernel  so       	$$&&&+++*d*00R00000000000r'   c                    K   d| _          | j        di | d{V \  }}| j                            d|            | j        |fi | d{V   | j        di | d{V  dS )az  Starts a kernel on this host in a separate process.

        If random ports (port=0) are being used, this method must be called
        before the channels are created.

        Parameters
        ----------
        `**kw` : optional
             keyword arguments that are passed down to build the kernel_cmd
             and launching the kernel (e.g. Popen kwargs).
        TNzStarting kernel: %sr&   )r8   r   r?   debugr   r   r   s      r(   _async_start_kernelz!KernelManager._async_start_kernel  s       !%;t;AAbAAAAAAAA
B 	,j999'd'
99b999999999+d+11b11111111111r'   c                 (  K   d|i}| j                             d|          }|                                  | j                             | j        |           | j        J | j                            |           d{V  t          j        | _	        dS )z+Send a shutdown request via control channelr   shutdown_requestcontentNr   )
r   msgr   sendr   ro   shutdown_requestedr   r   rV   )r4   r   r   r   s       r(   _async_request_shutdownz%KernelManager._async_request_shutdown  s      g&l17CC$$&&&$.444+++11'1BBBBBBBBB / ?r'   皙?waittimepollintervalc                   K   |t          | j        d          }| j        r| j                            |          }	 t	          j        |                     |          |dz             d{V  nZ# t          j        $ rH | j        	                    d           t          j        | _        |                                  d{V  Y nw xY w	 t	          j        |                     |          |dz             d{V  | j        r*| j        J | j                                         d{V  dS dS # t          j        $ rK | j        	                    d           t          j        | _        |                     |	           d{V  Y dS w xY w)
zWait for kernel shutdown, then kill process if it doesn't shutdown.

        This does not send shutdown requests - use :meth:`request_shutdown`
        first.
        Nr   )recommended)r   rM   timeoutz0Kernel is taking too long to finish, terminatingz,Kernel is taking too long to finish, killingr   )maxr{   ro   get_shutdown_wait_timer-   wait_for_async_waitTimeoutErrorr?   r   r   r   rV   _async_send_kernel_sigterm
has_kernelwaitr    _async_kill_kernel)r4   r   r   r   s       r(   _async_finish_shutdownz$KernelManager._async_finish_shutdown  s(      42A66H 	U'>>8>TTH	4"  l ;;XPQ\           # 	4 	4 	4HNNMNNN$3$BD!1133333333333	4
	."  l ;;XPQ\           .'333&++-----------. . # 	; 	; 	;HNNIJJJ$3$BD!))')::::::::::::	;s%   3A1 1ACC3D2 2AFFc                 :  K   |s|                                   |                                  |                                  d| j        _        | j        r|s| j                            d           | j        r#| j        	                    |           d{V  dS dS )z/Clean up resources when the kernel is shut downNr   )r   r   )
r   cleanup_ipc_filesr   r   r   rX   rY   destroyro   cleanupr4   r   s     r(   _async_cleanup_resourcesz&KernelManager._async_cleanup_resources  s       	+((***   ""$$$"  	- 	-L   ,,, 	<"**7*;;;;;;;;;;;	< 	<r'   nowc                 v  K   | j         sdS d| _        |                                  | j        r|                                  d{V  |r|                                  d{V  n8|                     |           d{V  |                     |           d{V  |                     |           d{V  dS )aZ  Attempts to stop the kernel process cleanly.

        This attempts to shutdown the kernels cleanly by:

        1. Sending it a shutdown message over the control channel.
        2. If that fails, the kernel is shutdown forcibly by sending it
           a signal.

        Parameters
        ----------
        now : bool
            Should the kernel be forcible killed *now*. This skips the
            first, nice shutdown attempt.
        restart: bool
            Will this kernel be restarted after it is shutdown. When this
            is True, connection files will not be cleaned up.
        NTr   )	r;   r   r   r  _async_interrupt_kernelr  r   r	  r  )r4   r  r   s      r(   _async_shutdown_kernelz$KernelManager._async_shutdown_kernel  s     &  	F!? 	1..000000000 	?))++++++++++..w.????????? --g->>>>>>>>>++G+<<<<<<<<<<<r'   newportsc                   K   | j         d}t          |          |                     |d           d{V  |r|                                  | j                             |            | j        di | j          d{V  dS )ay  Restarts a kernel with the arguments that were used to launch it.

        Parameters
        ----------
        now : bool, optional
            If True, the kernel is forcefully restarted *immediately*, without
            having a chance to do any cleanup action.  Otherwise the kernel is
            given 1s to clean up before a forceful restart is issued.

            In all cases the kernel is restarted, the only difference is whether
            it is given a chance to perform a clean shutdown or not.

        newports : bool, optional
            If the old kernel was launched with random ports, this flag decides
            whether the same ports and connection file will be used again.
            If False, the same ports and connection file are used. This is
            the default. If True, new random port numbers are chosen and a
            new connection file is written. It is still possible that the newly
            chosen random port numbers happen to be the same as the old ones.

        `**kw` : optional
            Any options specified here will overwrite those used to launch the
            kernel.
        Nz>Cannot restart the kernel. No previous call to 'start_kernel'.T)r  r   r&   )r   r/   r  cleanup_random_portsr   r   )r4   r  r  r   r   s        r(   _async_restart_kernelz#KernelManager._async_restart_kernel-  s      6 $RCs### ))c4)@@@@@@@@@ 	(%%''' 	  $$$&d&;;):;;;;;;;;;;;r'   c                     | j         S re   )rS   r^   s    r(   r;   zKernelManager.owns_kernelX  s      r'   c                 ,    | j         duo| j         j        S )z@Has a kernel process been started that we are actively managing.N)ro   r   r^   s    r(   r  zKernelManager.has_kernel\  s     t+L0@0LLr'   c                 p   K   | j         r,| j        J | j                            |           d{V  dS dS )zIsimilar to _kill_kernel, but with sigterm (not sigkill), but do not blockNr   )r  ro   	terminater  s     r(   r  z(KernelManager._async_send_kernel_sigterma  s[      ? 	>#///",,W,===========	> 	>r'   c                 ~  K   | j         r| j        J | j                            |           d{V  	 t          j        |                                 d           d{V  | j         r!| j                                         d{V  dS dS # t          j        $ r | j        	                    d           Y dS w xY wdS )zrKill the running kernel.

        This is a private method, callers should use shutdown_kernel(now=True).
        Nr   rx   r   z>Wait for final termination of kernel timed out - continuing...)
r  ro   killr-   r  r  r  r  r?   warningr  s     r(   r  z KernelManager._async_kill_kerneli  s     
 ? 	2#///"'''888888888	2&t'7'7'9'93GGGGGGGGGG ? 2*//111111111112 2 '     !abbb	2 	2s   .B )B:9B:c                 ~  K   | j         s| j        zt          | j        t                    rBt	          j        t          j        t          t          j	                 | j                            }n| j        }| j
        r| d{V  | d{V  | j         r| j        J | j        j        }|dk    r'|                     t          j                   d{V  dS |dk    rR| j                            di           }|                                  | j                            | j        |           dS dS d}t+          |          )zInterrupts the kernel by sending it a signal.

        Unlike ``signal_kernel``, this operation is well supported on all
        platforms.
        Nsignalmessageinterrupt_requestr   z.Cannot interrupt kernel. No kernel is running!)r  r9   r   r0   r-   ensure_futurerD   rH   r   r   r   r   interrupt_mode_async_signal_kernelr   SIGINTr   r   r   r   r   r/   )r4   r   r$  r   s       r(   r  z%KernelManager._async_interrupt_kernel  s[       		4;#:$+w// $-afVAE]DK.P.PQQ! KKKKKKK? 	$#///!-<N))//>>>>>>>>>>>9,,l&&':B&GG,,...!!$"6<<<<< -,
 CCs###r'   signumc                    K   | j         r+| j        J | j                            |           d{V  dS d}t          |          )a  Sends a signal to the process group of the kernel (this
        usually includes the kernel and any subprocesses spawned by
        the kernel).

        Note that since only SIGTERM is supported on Windows, this function is
        only useful on Unix systems.
        Nz+Cannot signal kernel. No kernel is running!)r  ro   send_signalr/   )r4   r'  r   s      r(   r%  z"KernelManager._async_signal_kernel  sc       ? 	$#///"..v66666666666?Cs###r'   c                    K   | j         sdS | j        r,| j        J | j                                         d{V }|dS dS )z$Is the kernel process still running?TNF)r;   r  ro   poll)r4   rets     r(   _async_is_alivezKernelManager._async_is_alive  sd       	4? 	#///(--////////C{tur'   c                    K   |                                   d {V r6t          j        |           d {V  |                                   d {V 4d S d S re   )r-  r-   r:   )r4   r   s     r(   r  zKernelManager._async_wait  s      
 ((******** 	.---------- ((******** 	. 	. 	. 	. 	.r'   )r+   Nr   re   )F)Nr   F)FF)r   )mr!   r"   r#   r$   rD   OptionalUnionr   r0   __annotations__r   rU   r   rX   r   r\   r]   rY   r   r_   r
   r`   r   r   rc   rf   r   r	   rj   rl   r   rn   ro   r   r   rs   rp   rt   r   rw   r   r{   r   r|   r   rv   
KernelSpecpropertyr   r   boolr   r   r   r   r   r   r   r   r   r   r   Callabler   r   r   r   r   Listr   r   r   _launch_kernelr   r   Tupler   pre_start_kernelr   post_start_kernelrI   r   start_kernelr   request_shutdownfloatr	  finish_shutdownr  cleanup_resourcesr  shutdown_kernelr  restart_kernelr;   r  r  _send_kernel_sigtermr  _kill_kernelr  interrupt_kernelintr%  signal_kernelr-  is_aliver  __classcell__rW   s   @r(   rK   rK   e   s6
         
 Jqwvw/0000ae qu       " "T%[[d((( !--GX---WY#+    
 &6%56& &L"     4l333ND333W. . . . . W^>AF38H3H,I >d > > > > (/wt'E'E'EIqwsG|$EEE
 6:K12999$,HZ-I$J$JJJJW"##Dj.J D D D $#D W"##!16#x-3H !T ! ! ! ^ $#! !&+! ! !    *11N)O)OKg&OOOW]=16#s(+; = = = = =
 7;L!*Z23:::!QZ
(=> ! ! ! X!
 `  K    W]'d ' ' ' ' qww/    X D4 D D D XD 261F1F1FL!*-.FFF355OS   ceeJT R  K     M4' ' ' '      6 6QZ 6 6TX 6 6 6 69 9
 93 9W[ 9 9 9 9)qu ))= ) ) ) )&1S!1 1d 1 1 1 1*)6 )6AF3K1H )6TUTZ[^T_ )6 )6 )6 )6V9QVC[ 9 9RV 9 9 9 9 X233N. . . .
$ $ $ $E	
afS!%Z00	1   :  x 788115 1T 1 1 1 1 !!9::2ae 2 2 2 2 2( 8/00L	@ 	@T 	@d 	@ 	@ 	@ 	@  x 788 '+!	%. %.*U#%. %. 	%.
 
%. %. %. %.N h566O< <d <t < < < < !!9::%= %= %=t %=X\ %= %= %= %=N h566O 38'< '<'<+/'<?@u'<	'< '< '< '<R X344N!T ! ! ! X! MD M M M XM> > > > > > > $8$>??2 2 2 2 2 2 2* 8.//L$ $ $ $>  x 788$ $ $ $ $ $ H122M
t 
 
 
 
 x((H. .e .d . . . . . . . .r'   rK   c                       e Zd ZU dZ ed          Zeed<    ed          Zeed<    e	e
j        j                  Ze	ed<    ed          de
j        j        fd            Zd	ej        def fd
Zej        Zej        Zej        dej        f         ed<   ej        Zej        dej        f         ed<   ej        Zej        dej        f         ed<   ej        Z ej        dej        f         ed<   ej!        Z"ej        dej        f         ed<   ej#        Z$ej        dej        f         ed<   ej%        Z&ej        dej        f         ed<   ej'        Z(ej        dej        f         ed<   ej)        Z*ej+        Z,ej-        Z.ej        dej        f         ed<   ej/        Z0ej        dej        f         ed<   ej1        Z2ej        dej        f         ed<    xZ3S )AsyncKernelManagerzAn async kernel manager.z-jupyter_client.asynchronous.AsyncKernelClientr`   ra   rc   rY   r+   c                 L    d| _         t          j                                        S r[   )rX   r\   r-   r]   r^   s    r(   r_   z#AsyncKernelManager._context_default  s     ${""$$$r'   r6   c                 6     t                      j        di |S )zGet a client for the manager.r&   )rT   r   )r4   r6   rW   s     r(   r   zAsyncKernelManager.client  s!     uww~'''''r'   .r;  r9  r:  r<  r>  r?  r@  rA  rD  rF  rG  )4r!   r"   r#   r$   r
   r`   r1  r   rc   r   r\   r-   r]   rY   r   r_   rD   r   r   r   rK   r   r7  r   r;  r5  	Awaitabler   r9  r   r:  r   r<  r	  r>  r  r?  r  r@  r  rA  r  rB  r  rC  r  rD  r%  rF  r-  rG  rH  rI  s   @r(   rK  rK    sy        "" &6%57& &L"     4&UVVVNDVVV !!455GX555WY%#+"5 % % % %((	( ( ( ( ( ( #7N1>1RL!*S!+-.RRR5B5Zajak!12ZZZ6C6\qz#q{"23\\\5B5Zajak!12ZZZ4A4XOQZQ[ 01XXX6C6\qz#q{"23\\\4A4XOQZQ[ 01XXX3@3VNAJsAK/0VVV(C 3L5B5Zajak!12ZZZ2?2TM1:c1;./TTT-:-JHajak)*JJJJJJJr'   rK  <   r~   startup_timeoutr|   r6   c                 2   t          |          } |j        di | |                                }|                                 	 |                    |            n7# t
          $ r* |                                 |                                  w xY w||fS )5Start a new kernel, and return its Manager and Clientr   r   r&   )rK   r;  r   start_channelswait_for_readyr/   stop_channelsr@  rP  r|   r6   kmkcs        r(   start_new_kernelrY    s     
;	/	/	/BBOf	B
/2222   


 r6Ms   A 4Bc                 Z  K   t          |          } |j        di | d{V  |                                }|                                 	 |                    |            d{V  n=# t
          $ r0 |                                 |                                 d{V   w xY w||fS )rR  r   Nr   r&   )rK  r;  r   rS  rT  r/   rU  r@  rV  s        r(   start_new_async_kernelr[    s       
	4	4	4B
"/
#
#F
#
########	B8888888888   
  """""""""
 8Os   A, ,:B&c               +      K   t          di | \  }}	 |V  |                                 |                    d           dS # |                                 |                    d           w xY w)zContext manager to create a kernel in a subprocess.

    The kernel is shut down when the context exits.

    Returns
    -------
    kernel_client: connected KernelClient instance
    T)r  Nr&   )rY  rU  r@  )r6   rW  rX  s      r(   
run_kernelr]    s       ''''FB%

t$$$$$ 	
t$$$$s   A ,A/)rO  r~   )Er$   r-   rF   r   r   r   r   typingrD   r   rO   asyncio.futuresr   concurrent.futuresr0   
contextlibr   enumr   r\   jupyter_core.utilsr   	traitletsr   r   r	   r
   r   r   r   r   r   r   r   traitlets.utils.importstringr   r   r   asynchronousr   blockingr   r   r   connectr   
managerabcr   provisioningr   r   r   r   TypeVarr5  r)   r0  r1   rI   rK   rK  registerr=  rj   r8  rY  r[  Iteratorr]  r&   r'   r(   <module>rn     s   + +      				 				  



       " " " " " " 0 0 0 0 0 0 % % % % % %       



 ' ' ' ' ' '                          5 4 4 4 4 4       + + + + + + * * * * * *             ( ( ( ( ( ( ( ( ( ( ( ( / / / / / / 9 9 9 9 9 9& & & & &d & & & AIcCJ/000QWVW_-    Q 1    8a	. a	. a	. a	. a	.' a	. a	. a	.H$K $K $K $K $K $K $K $KN   - ( ( ( 5= .1HIW]001   & 5= .1HIW!223   $ % %1:l#; % % % % % %r'   