
    <e(                        	 d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlZej	        dd         dk    r e j
        dej	        z             ej                    Z ej                    Zej        j        dk    oej        j        dk    Zd Zd	 Zd
 Z ej                     e j         eed          d           G d de j                                          Zd Zedk    r e j                     dS dS )    N)threading_helper   winzCan't test signal on %spthreadz
mutex+condc                     t          j         t           j        |           }t          j         t           j        |          }t          j         t           j        |          }|||fS N)signalSIGUSR1SIGUSR2SIGALRM)for_usr1for_usr2for_alrmusr1usr2alrms         ./usr/lib/python3.11/test/test_threadsignals.pyregisterSignalsr      sH    =22D=22D=22Dt    c                 ~    t           |          dxx         dz  cc<   t          j                    t           |          d<   d S )Ntripped   
tripped_by)signal_blackboardthread	get_ident)sigframes     r   handle_signalsr      sB    c9%%%*%%%+1+;+=+=c<(((r   c                      t          j        t          t          j                   t          j        t          t          j                   t                                           d S r   )oskillprocess_pidr	   r
   r   signalled_allrelease r   r   send_signalsr'   "   sB    GK(((GK(((r   alarmztest requires signal.alarmc                   L   e Zd Zd Zd Zd Z ej        ed           ej        e	j
                            d          oe	j        j         d           ej        e	j
                            d          d          d	                                     Z ej        ed           ej        e	j
                            d          oe	j        j         d           ej        e	j
                            d          d          d
                                     Zd Zd Zd Zd ZdS )ThreadSignalsc                    t          j                    5  t                                           |                                  t                                           d d d            n# 1 swxY w Y   t
          t          j                 d         dk    s!t
          t          j                 d         dk    rV	 t          j	        d           t          j
                     t          j	        d           n# t          j	        d           w xY w|                     t
          t          j                 d         d           |                     t
          t          j                 d         t          j                               |                     t
          t          j                 d         d           |                     t
          t          j                 d         t          j                               t                                           d S )Nr   r   r   r   )r   wait_threads_exitr$   acquirespawnSignallingThreadr   r	   r
   r   r(   pauseassertEqualr   r   r%   selfs    r   test_signalszThreadSignals.test_signals,   s   /11 	$ 	$
 !!###&&(((!!###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ V^,Y71<</	:a?? QQQ+FN;IFJJJ+FN;LI!+--	/ 	/ 	/+FN;IFJJJ+FN;LI!+--	/ 	/ 	/s   AA''A+.A+5'C1 1Dc                 :    t          j        t          d           d S )Nr&   )r   start_new_threadr'   r1   s    r   r.   z#ThreadSignals.spawnSignallingThreadL   s    b11111r   c                     t           r   )KeyboardInterrupt)r2   r   r   s      r   alarm_interruptzThreadSignals.alarm_interruptO   s    r   z/POSIX condition variables cannot be interruptedlinuxzBIssue 34004: musl does not allow interruption of locks by signals.openbsdz%lock cannot be interrupted on OpenBSDc                 ^   t          j         t           j        | j                  }	 t          j                    }|                                 t          j        d           t          j                    }| 	                    t          |j        d           t          j                    |z
  }|                     |d           t          j        d           t          j         t           j        |           d S # t          j        d           t          j         t           j        |           w xY w)Nr      timeout      @r   )r	   r   r8   r   allocate_lockr-   r(   time	monotonicassertRaisesr7   
assertLess)r2   oldalrmlockt1dts        r   test_lock_acquire_interruptionz,ThreadSignals.test_lock_acquire_interruptionR   s     -0DEE	3'))DLLNNNLOOO!!B/qIII!!B&B
 OOB$$$LOOOM&.'22222 LOOOM&.'2222s   BC7 75D,c                 j   t          j         t           j        | j                  }	 t          j                    fd}t          j                    5  t          j        |d                               d          r>	                                 t          j        d                               d          >t          j        d           t          j                    }|                     t          j        d           t          j                    |z
  }|                     |d	           d d d            n# 1 swxY w Y   t          j        d
           t          j         t           j        |           d S # t          j        d
           t          j         t           j        |           w xY w)Nc                  0                                       d S r   )r-   )rlocks   r   other_threadzCThreadSignals.test_rlock_acquire_interruption.<locals>.other_thread   s    r   r&   Fblocking{Gz?r   r<   r=   r?   r   )r	   r   r8   r   RLockr   r,   r5   r-   r%   rA   sleepr(   rB   rC   r7   rD   )r2   rE   rM   rG   rH   rL   s        @r   test_rlock_acquire_interruptionz-ThreadSignals.test_rlock_acquire_interruptionq   s    -0DEE	3LNNE          "355 ) )'b999mmUm33 %MMOOOJt$$$ mmUm33 % Q^%%!!"3U]A!NNN^%%*C((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) LOOOM&.'22222 LOOOM&.'2222s0   +E= CD=1E= =EE= EE= =5F2c                     d _          fd}t          j        t          j        |          }	 fd}t          j                    5  t          j        |d                               d          r>                                 t          j
        d                               d          >                                }                      j                                         |           d d d            n# 1 swxY w Y   t          j        t          j        |           d S # t          j        t          j        |           w xY w)NFc                     d_         d S )NT)	sig_recvd)r	   r   r2   s     r   
my_handlerz9ThreadSignals.acquire_retries_on_intr.<locals>.my_handler   s    !DNNNr   c                                                         t          j        d           t          j        t
          t          j                   t          j        d                                             d S )N      ?)	r-   rA   rR   r!   r"   r#   r	   r
   r%   )rF   s   r   rM   z;ThreadSignals.acquire_retries_on_intr.<locals>.other_thread   sU      
3V^444 
3r   r&   rN   rP   )rV   r	   r
   r   r,   r   r5   r-   r%   rA   rR   
assertTrue)r2   rF   rW   old_handlerrM   results   ``    r   acquire_retries_on_intrz%ThreadSignals.acquire_retries_on_intr   s   	" 	" 	" 	" 	" mFNJ??	7     "355 ( ('b999llEl22 %LLNNNJt$$$ llEl22 % ///'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( M&.+66666FM&.+6666s0   D, B-D 4D,  DD, DD, ,!Ec                 R    |                      t          j                               d S r   )r]   r   r@   r1   s    r   !test_lock_acquire_retries_on_intrz/ThreadSignals.test_lock_acquire_retries_on_intr   s%    $$V%9%;%;<<<<<r   c                 R    |                      t          j                               d S r   )r]   r   rQ   r1   s    r   "test_rlock_acquire_retries_on_intrz0ThreadSignals.test_rlock_acquire_retries_on_intr   s"    $$V\^^44444r   c                 6    d  _         d  _        d _        t          j                                                     t          j                                                      fd}t          j        t          j        |          }	  fd}fd}t          j	                    5  t          j
        |d            |                                                                    j         j         z
  d                                 j         j         z
  d                                 j        d           d d d            n# 1 swxY w Y   t          j        t          j        |           d S # t          j        t          j        |           w xY w)Nr   c                 (    xj         dz  c_         d S )Nr   )
sigs_recvd)signumr   r2   s     r   rW   z@ThreadSignals.test_interrupted_timed_acquire.<locals>.my_handler   s    OOq OOOOr   c                      t          j                    _                             d           t          j                    _        d S )NrY   r=   )rA   rB   startr-   end)rF   r2   s   r   timed_acquirezCThreadSignals.test_interrupted_timed_acquire.<locals>.timed_acquire   s9    !^--
S)))>++r   c                      t          d          D ]:} t          j        d           t          j        t
          t          j                   ;                                 d S )N(   g{Gz?)	rangerA   rR   r!   r"   r#   r	   r
   r%   )_dones    r   r'   zBThreadSignals.test_interrupted_timed_acquire.<locals>.send_signals   sP    r 9 9AJt$$$GK8888r   r&   g       @g333333?)rg   rh   rd   r   r@   r-   r	   r
   r   r,   r5   rD   assertGreater)r2   rW   r[   ri   r'   rn   rF   s   `    @@r   test_interrupted_timed_acquirez,ThreadSignals.test_interrupted_timed_acquire   s    
#%%#%%	! 	! 	! 	! 	!mFNJ??	7, , , , , ,     "355 7 7 'b9994: 5s;;;""48dj#8#>>> ""4?A6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 M&.+66666FM&.+6666s1   E7 *BE?E7 EE7 EE7 7!FN)__name__
__module____qualname__r3   r.   r8   unittestskipIfUSING_PTHREAD_CONDsysplatform
startswiththread_infoversionrI   rS   r]   r_   ra   rp   r&   r   r   r*   r*   (   s            @2 2 2      X_'FH HX_S\,,W55 100#$ $
 X_S\,,Y77<> >3 3> >$ $H H3, X_'FH HX_S\,,W55 100#$ $
 X_S\,,Y77<> >3 3> >$ $H H3:7 7 7@= = =5 5 5,7 ,7 ,7 ,7 ,7r   r*   c                      t           j        dddt           j        dddt           j        dddiat          t          t          t                    } t          j        t
          g| R   d S )Nr   )r   r   )	r	   r
   r   r   r   r   r   rt   addModuleCleanup)oldsigss    r   setUpModuler      sl     !.q+K+K .q+K+K .q+K+KN nnnMMGo8888888r   __main__)rt   r	   r!   rw   test.supportr   _threadr   rA   rx   SkipTestgetpidr#   r@   r$   rz   namerF   rv   r   r   r'   requires_working_threading
skipUnlesshasattrTestCaser*   r   rq   mainr&   r   r   <module>r      s   <   				 



 ) ) ) ) ) )     L!
(
5D
E
EEbikk"f"$$o*i7 ?/.,>   > > >
   -,..WWVW--/KLL7 7 7 7 7H% 7 7 ML /.7D9 9 9 zHMOOOOO r   