
                         n    S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSKJ	r	  SSK
Jr   " S	 S
\5      rg)zIContext manager to help with Control-C handling during critical commands.    )absolute_import)division)unicode_literalsN	exit_code)
exceptions)logc                   0    \ rS rSrSrS rS rS rS rSr	g)	CancellableTestSection   zCancel a test matrix if CTRL-C is typed during a section of code.

While within this context manager, the CTRL-C signal is caught and a test
matrix is cancelled. This should only be used with a section of code where
the test matrix is running.
c                 ,    S U l         S U l        Xl        g N)_old_sigint_handler_old_sigterm_handler_matrix_monitor)selfmatrix_monitors     :lib/googlecloudsdk/api_lib/firebase/test/ctrl_c_handler.py__init__CancellableTestSection.__init__%   s    #D $D)    c                 f   [         R                  " [         R                  5      U l        [         R                  " [         R                  5      U l        [         R                   " [         R                  U R                  5        [         R                   " [         R                  U R                  5        U $ r   )signal	getsignalSIGINTr   SIGTERMr   _Handler)r   s    r   	__enter__ CancellableTestSection.__enter__*   sa    %//>D & 0 0 @D
MM&--/
MM&..$--0Kr   c                     [         R                   " [         R                  U R                  5        [         R                   " [         R                  U R                  5        g)NF)r   r   r   r   r   )r   typvalue	tracebacks       r   __exit__CancellableTestSection.__exit__1   s5    
MM&--!9!9:
MM&..$";";<r   c                 8   [         R                  R                  SR                  U R                  R
                  S95        U R                  R                  5         [         R                  R                  S5        [        R                  " [        R                  S9e)Nz

Cancelling test [{id}]...

)idz!
Test matrix has been cancelled.
r   )r	   statuswriteformatr   	matrix_idCancelTestMatrixr   ExitCodeNoErrorr   MATRIX_CANCELLED)r   unused_signalunused_frames      r   r   CancellableTestSection._Handler6   sl    JJ8f 4 4 > >f?A))+JJ:;

$
$y/I/I
JJr   )r   r   r   N)
__name__
__module____qualname____firstlineno____doc__r   r   r$   r   __static_attributes__ r   r   r   r      s    *

Kr   r   )r6   
__future__r   r   r   r   $googlecloudsdk.api_lib.firebase.testr   googlecloudsdk.callioper   googlecloudsdk.corer	   objectr   r8   r   r   <module>r>      s.     P &  '  : . #KV Kr   