
    Mh+                         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m	Z	 d dl
mZmZmZ  ej                    Z e            Z ej                    Z G d de	j                  Zd Zd Zd	 ZdS )
    N)common)logutil)
components	launchersserversc                   v     e Zd ZdZ ej        d          Z fdZd Zd Z	d Z
d Zd Zdd
ZddZd Z xZS )SessionzA debug session involving a client, an adapter, a launcher, and a debug server.

    The client and the adapter are always present, and at least one of launcher and debug
    server is present, depending on the scenario.
       c                 0    ddl m} t                                                       t	          j                     _        t           j                   _	        t	          j
         j                   _        t          j         |j                   _        	 t          j         t           j                   _        	 t          j         t&          j                   _        	 d  _        	 d  _        	 i  _        	 d _        	  xj         fdgz  c_        d S )Nr   )clientsFc                  ,                                     S N)notify_changed)_selfs    X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/debugpy/adapter/sessions.py<lambda>z"Session.__init__.<locals>.<lambda>@   s    d&9&9&;&;     )debugpy.adapterr   super__init__	threadingRLocklocknext_counterid	Condition_changed_conditionr   missingClientclientr   Launcherlauncherr   Serverserverno_debugpiddebug_optionsis_finalizing	observers)r   r   	__class__s   ` r   r   zSession.__init__   s    ++++++O%%	t}%%"+"5di"@"@ (w~>>3"*41CDD	 !(w~>>	 21I"2;;;;<<r   c                     d| j          dS )NzSession[]r   r   s    r   __str__zSession.__str__B   s    $$'$$$$r   c                 8    | j                                          | S )z&Lock the session for exclusive access.)r   acquirer1   s    r   	__enter__zSession.__enter__E   s    	r   c                 8    | j                                          dS )zUnlock the session.N)r   release)r   exc_type	exc_valueexc_tbs       r   __exit__zSession.__exit__J   s    	r   c                     t           5  t                              |            t                                           d d d            d S # 1 swxY w Y   d S r   )_lock	_sessionsadd_sessions_changedsetr1   s    r   registerzSession.registerN   s     	$ 	$MM$!!###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   4A		AAc                    | 5  | j                                          d d d            n# 1 swxY w Y   | j        | j        | j        f}t          d |D                       rst          5  | t          v rHt          j	        d|            t          
                    |            t                                           d d d            d S # 1 swxY w Y   d S d S )Nc              3   ,   K   | ]}| p|j          V  d S r   )is_connected).0coms     r   	<genexpr>z)Session.notify_changed.<locals>.<genexpr>Z   s/      EE33w.c..EEEEEEr   z{0} has ended.)r    
notify_allr#   r%   r'   allr=   r>   r   inforemover@   rA   )r   r   s     r   r   zSession.notify_changedS   s]    	1 	1#..000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1
 [$-<
EE*EEEEE 	, , ,9$$H-t444$$T***%))+++	, , , , , , , , , , , , , , , , , ,	, 	,s   )--(ACCCNc                 J     fdd_         1t          j        d          }d|_        |                                  5   |            s8j         r	 ddd           dS  j                                          |            8	 ddd           dS # 1 swxY w Y   dS )a`  Waits until predicate() becomes true.

        The predicate is invoked with the session locked. If satisfied, the method
        returns immediately. Otherwise, the lock is released (even if it was held
        at entry), and the method blocks waiting for some attribute of either self,
        self.client, self.server, or self.launcher to change. On every change, session
        is re-locked and predicate is re-evaluated, until it is satisfied.

        While the session is unlocked, message handlers for components other than
        the one that is waiting can run, but message handlers for that one are still
        blocked.

        If timeout is not None, the method will unblock and return after that many
        seconds regardless of whether the predicate was satisfied. The method returns
        False if it timed out, and True otherwise.
        c                  f    t          j                   d_                                          d S )NT)timesleep	timed_outr   )r   timeoutwait_for_timeouts   r   rS   z*Session.wait_for.<locals>.wait_for_timeouts   s4    Jw)-&!!!!!r   FNzSession.wait_for() timeout)targetnameT)rQ   r   Threaddaemonstartr    wait)r   	predicaterR   threadrS   s   ` ` @r   wait_forzSession.wait_fora   sF   $	" 	" 	" 	" 	" 	" 	"
 &+"%'.J  F !FMLLNNN 	 	ikk /#- ! 	 	 	 	 	 	 	 	 ',,...  ikk / 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   B'$BBBc                 J   | j         rdS d| _         t          j        d||            |t          | j                  }	 |                     ||           n9# t          $ r, t          j        d|            t          j	        d           Y nw xY wt          j        d|            dS )a  Finalizes the debug session.

        If the server is present, sends "disconnect" request with "terminateDebuggee"
        set as specified request to it; waits for it to disconnect, allowing any
        remaining messages from it to be handled; and closes the server channel.

        If the launcher is present, sends "terminate" request to it, regardless of the
        value of terminate; waits for it to disconnect, allowing any remaining messages
        from it to be handled; and closes the launcher channel.

        If the client is present, sends "terminated" event to it.

        If terminate_debuggee=None, it is treated as True if the session has a Launcher
        component, and False otherwise.
        NTz{0}; finalizing {1}.z Fatal error while finalizing {0}r   z{0} finalized.)
r+   r   rK   boolr%   	_finalize	Exceptionswallow_exceptionos_exit)r   whyterminate_debuggees      r   finalizezSession.finalize   s    "  	F!'d333%!%dm!4!4	NN3 23333 	 	 	 !"DdKKKHQKKKKK		 	!4(((((s   A 3B
Bc                     t          j                      j        r j        j        rc|r- j        r& j        j        r j                                         n4	  j        j                            dd|i           n# t          $ r Y nw xY w j        	                                  j        r j        j        r j        r_ j        j
        j        sNt          j        d                                  fdt          j                  st          j        d             j        r j        j
        j        s j                                         t          j        d  j                                         fd           	  j        j                                         n## t          $ r t          j                     Y nw xY w j        r j        j        rEi } j        j        rd	|d
<   	  j        j                            d|           n# t          $ r Y nw xY w j        j        I j        j        j        dk    r5 j        r j        j
        j        st          j                     t          j        d           t5                       j        r+ j        j                             j        j                   	 fdt          j                    D             }t=          |          sd S |D ]|}t          j        d|           	 t?          j         |j        tB          j"                   n%# t          $ r t          j        d|           Y nw xY w                    |j                   }d S d S d S d S )N
disconnectterminateDebuggeez!{0} waiting for "exited" event...c                        j         j        d uS r   )r%   	exit_coder1   s   r   r   z#Session._finalize.<locals>.<lambda>   s    DM34? r   )rR   z){0} timed out waiting for "exited" event.z${0} waiting for {1} to disconnect...c                       j         j         S r   )r%   rE   r1   s   r   r   z#Session._finalize.<locals>.<lambda>   s    dm&@"@ r   Trestart
terminatedlaunchz>"launch" session ended - killing remaining debuggee processes.c                 &    g | ]}|j         v|S  r)   )rF   connpids_killeds     r   
<listcomp>z%Session._finalize.<locals>.<listcomp>   s0        8;66 666r   zKilling {0}zFailed to kill {0})#r   dont_wait_for_first_connectionr'   rE   r%   re   channelrequestr`   detach_from_session
connectionprocess_replacedr   rK   r\   r   PROCESS_EXIT_TIMEOUTwarningclosera   r#   restart_requested
send_eventstart_requestcommandstop_servingrA   r)   r?   connectionslenrb   killsignalSIGTERM)r   rd   re   bodyconnsrs   rt   s   `     @r   r_   zSession._finalize   s    	.000; 	.{' % $- DM<V  M446666+33(+>@R*S    %   K++---= 	(T]7 	( { S4;#9#J S<dCCC}}????"7 %   S K KTRRR K 3DK$:$K 300222 H;T4=QQQMM@@@@AAA(%++---- ( ( (%'''''( ; )	2{' 	 ;0 +&*DOK'22<FFFF    D )5K-5AA B)-)?)P B $&&&T   "ee= 7T]%6%BOODM$56662   $+$7$9$9  E
 u::  % 2 2555NGDHfn====( N N N12FMMMMMN#111127)	2 )	2 65AAAAsH   "A< <
B	B	F$ $GG/ H 
HH$L33MMr   )__name__
__module____qualname____doc__	itertoolscountr   r   r2   r5   r;   rB   r   r\   rf   r_   __classcell__)r-   s   @r   r
   r
      s          yq!!H"= "= "= "= "=H% % %  
  $ $ $
, , ,$ $ $ $L!) !) !) !)F`2 `2 `2 `2 `2 `2 `2r   r
   c                      t           5  t           fdt          D             d           cd d d            S # 1 swxY w Y   d S )Nc              3   2   K   | ]}|j         k    |V  d S r   rr   )rF   sessionr)   s     r   rH   zget.<locals>.<genexpr>  s/      LL9K9KW9K9K9K9KLLr   )r=   r   r>   rr   s   `r   getr     s    	 T TLLLLILLLdSST T T T T T T T T T T T T T T T T Ts   !7;;c                      	 t           5  t          t                    s	 ddd           dS t                                           ddd           n# 1 swxY w Y   t                                           t)zvBlocks until all sessions have ended.

    A session ends when all components that it manages disconnect from it.
    TN)r=   r   r>   r@   clearrY   rq   r   r   wait_until_endedr     s    
! 	& 	&y>> 	& 	& 	& 	& 	& 	& 	& 	& ##%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	   !s   AAAAc                      t           sd S t          t           d           d         } | j        }||                                 d S d S )Nc                     | j         S r   r0   )r   s    r   r   z report_sockets.<locals>.<lambda>"  s    GJ r   )keyr   )r>   sortedr#   report_sockets)r   r#   s     r   r   r     sW     Y$>$>???BG^F r   )r   rb   r   r   rO   debugpyr   debugpy.commonr   r   r   r   r   r   r   r=   rA   r>   Eventr@   
Observabler
   r   r   r   rq   r   r   <module>r      s  
     				             $ $ $ $ $ $ $ $ : : : : : : : : : : 		CEE	#IO%% u2 u2 u2 u2 u2do u2 u2 u2pT T T

! 
! 
!         r   