+
    Biٔ                        R t ^ RIt^ RIt^ RIt^ RIHtHt ^ RIt^ RIt^ RI	t	^ RI
Ht ^ RIHt ]P                  ! ]P                  R4      tR t ! R R]4      t ! R	 R
]P(                  4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      tR# )z/
Various tests for synchronization primitives.
N)start_new_threadTIMEOUT_MAX)support)threading_helperz9platform doesn't support fork (no _at_fork_reinit method)c                 @    \         P                  ! R V ,          4       R# ){Gz?N)timesleep)nthreads   &&/usr/lib/python3.14/test/lock_tests.pywait_threads_blockedr      s     	JJuw    c                   F   a  ] tR t^t o RtR	R ltR tR tR tR t	Rt
V tR# )
Bunchz
A bunch of threads.
c                n    Wn         W n        . V n        . V n        . V n        V'       * V n        RV n        R# )z
Construct a bunch of `nthread` threads running the same function `func`.
If `wait_before_exit` is True, the threads won't terminate until
do_finish() is called.
N)funcr
   startedfinished
exceptions	_can_exit_wait_thread)selfr   r
   wait_before_exits   &&&&r   __init__Bunch.__init__    s5     	-- r   c                b   \         P                  ! 4       pV P                  P                  V4        V P	                  4        V P                  P                  V4       \        P                  ! \        P                  4       F  pV P                  '       g   K   R # 	  R #   \
         d&   pT P                  P                  T4        R p?LR p?ii ; i  T P                  P                  T4       \        P                  ! \        P                  4       F  pT P                  '       g   K   i 	  i ; iN)	threading	get_identr   appendr   BaseExceptionr   r   r   sleeping_retrySHORT_TIMEOUTr   )r   tidexc_s   &   r   task
Bunch.task.   s    !!#C 	IIK MM  %++G,A,AB>>> C	  	(OO""3''	( MM  %++G,A,AB>>> Cs0   B C*C
C 
CC AD.)D.c                   \         P                  ! \        P                  4      V n        V P                  P                  4         \        V P                  4       F  p\        V P                  R4       K  	  \        P                  ! \        P                  4       F*  p\        T P                  4      T P                  8  g   K)   T # 	  T #    R T n
        h ; i)T )r   wait_threads_exitr   r"   r   	__enter__ranger
   r   r&   r   r!   lenr   )r   r%   s   & r   r+   Bunch.__enter__;   s    ,>>w?T?TU##%	4<<( B/ ) ''(=(=>A4<< DLL0	 ? 	!DNs   2C 
Cc                J   \         P                  ! \         P                  4       F)  p\        V P                  4      V P
                  8  g   K)   M	  V P                  P                  R R R 4       V P                  pR V n        V'       d   \        V P                   R2V4      hR # )Nz threads raised exceptions)r   r!   r"   r-   r   r
   r   __exit__r   ExceptionGroupr   )r   exc_type	exc_value	tracebackr%   r   s   &&&&  r   r0   Bunch.__exit__L   s    ''(=(=>A4==!T\\1 ?
 	""4t4 __
 DII;.H!I!+- - r   c                    R V n         R# TN)r   r   s   &r   	do_finishBunch.do_finish[   s	    r   )r   r   r   r   r   r
   r   N)F)__name__
__module____qualname____firstlineno____doc__r   r&   r+   r0   r9   __static_attributes____classdictcell____classdict__s   @r   r   r      s(     !"- r   r   c                   2   a  ] tR t^_t o R tR tR tRtV tR# )BaseTestCasec                :    \         P                  ! 4       V n        R # r   )r   threading_setup_threadsr8   s   &r   setUpBaseTestCase.setUp`   s    (88:r   c                l    \         P                  ! V P                  !   \        P                  ! 4        R # r   )r   threading_cleanuprH   r   reap_childrenr8   s   &r   tearDownBaseTestCase.tearDownc   s     **DMM:r   c                f    V P                  WR ,          4       V P                  WR,          4       R# )g333333?g      $@N)assertGreaterEqual
assertLess)r   actualexpecteds   &&&r   assertTimeoutBaseTestCase.assertTimeoutg   s&     	3740r   )rH   N)	r;   r<   r=   r>   rI   rN   rU   r@   rA   rB   s   @r   rE   rE   _   s     ; 1 1r   rE   c                   x   a  ] tR t^pt o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tRtV tR# )BaseLockTestsz3
Tests for both recursive and non-recursive locks.
c                    \         P                  ! \         P                  4       F  p\        V4      V8  g   K   M	  V P	                  \        V4      V4       R # r   )r   r!   r"   r-   assertEqual)r   phaserT   r%   s   &&& r   
wait_phaseBaseLockTests.wait_phaseu   sB    ''(=(=>A5zX% ? 	UX.r   c                (    V P                  4       p?R # r   )locktyper   locks   & r   test_constructorBaseLockTests.test_constructor{   s    }}r   c                ^    V P                  4       pV P                  \        V4      R 4       ?R# )z<unlocked .* object (.*)?at .*>N)r_   assertRegexreprr`   s   & r   	test_reprBaseLockTests.test_repr   s%    }}d%FGr   c                ~    V P                  4       pVP                  4        V P                  \        V4      R 4       ?R# )z<locked .* object (.*)?at .*>N)r_   acquirere   rf   r`   s   & r   test_locked_reprBaseLockTests.test_locked_repr   s.    }}d%DEr   c                H    V P                  4       pVP                  4        ?R # r   )r_   rj   r`   s   & r   test_acquire_destroy"BaseLockTests.test_acquire_destroy   s    }}r   c                h    V P                  4       pVP                  4        VP                  4        ?R # r   r_   rj   releaser`   s   & r   test_acquire_release"BaseLockTests.test_acquire_release   s"    }}r   c                    V P                  4       pV P                  VP                  R 4      4       VP                  4        R# FN)r_   
assertTruerj   rr   r`   s   & r   test_try_acquireBaseLockTests.test_try_acquire   s+    }}U+,r   c                  aa V P                  4       oSP                  4        . oVV3R  lp\        V^4      ;_uu_ 4         RRR4       V P                  S^ ,          4       SP	                  4        R#   + '       g   i     L:; i)c                  H   < SP                  S P                  R 4      4       R# rv   r   rj   ra   results   r   f3BaseLockTests.test_try_acquire_contended.<locals>.f   s    MM$,,u-.r   N)r_   rj   r   assertFalserr   r   r   ra   r~   s   & @@r   test_try_acquire_contended(BaseLockTests.test_try_acquire_contended   sW    }}	/1a[[ # [s    A44B	c                  a V P                  4       oSP                  4        V3R  lp^p\        W4      ;_uu_ 4       p\        V4       V P	                  \        VP                  4      ^ 4       SP                  4        RRR4       V P	                  \        XP                  4      V4       R#   + '       g   i     L7; i)c                  H   < S P                  4        S P                  4        R # r   rj   rr   ra   s   r   r   /BaseLockTests.test_acquire_contended.<locals>.f       LLNLLNr   N)r_   rj   r   r   rZ   r-   r   rr   )r   r   Nbunchra   s   &   @r   test_acquire_contended$BaseLockTests.test_acquire_contended   s    }}	 1[[E #S0!4 LLN  	U^^,a0 [s   AB--B=	c           	       a V P                  4       oV3R  lpRV3R llpS;_uu_ 4         RRR4       \        V^4      ;_uu_ 4         RRR4       V P                  \        4      ;_uu_ 4        S;_uu_ 4        \        h  + '       g   i     L]; i  + '       g   i     LR; i  + '       g   i     M; i RRR4       M  + '       g   i     M; i\        T^4      ;_uu_ 4         RRR4       R#   + '       g   i     R# ; i)c                  H   < S P                  4        S P                  4        R # r   r   r   s   r   r   "BaseLockTests.test_with.<locals>.f   r   r   Nc                 d   < S;_uu_ 4        V e   V h R R R 4       R #   + '       g   i     R # ; ir   r)   )errra   s   &r   	with_lock*BaseLockTests.test_with.<locals>.with_lock   s#    ?I # s   /	r   )r_   r   assertRaises	TypeError)r   r   r   ra   s   &  @r   	test_withBaseLockTests.test_with   s    }}		 T  1a[[  y)) T [
  *))) 1a[[ [[[sA   BB/C:B'	B	B$	'B72CC	+C77D	c                   a V P                  4       oV3R  lp\        V^4      ;_uu_ 4         RRR4       R#   + '       g   i     R# ; i)c                  H   < S P                  4        S P                  4        R # r   r   r   s   r   r   )BaseLockTests.test_thread_leak.<locals>.f   r   r   N)r_   r   r   r   ra   s   & @r   test_thread_leakBaseLockTests.test_thread_leak   s1     }}	 1b\\ \\\s	   8A		c                8  aa V P                  4       oV P                  \        SP                  R ^4       V P                  \        SP                  RR7       V P                  \        SP                  RR7       V P                  \        SP                  \
        ^,           R7       SP                  \
        R7       SP                  4        \        P                  ! 4       pV P                  SP                  ^R7      4       \        P                  ! 4       pV P                  W!,
          ^4       . oVV3R lp\        V^4      ;_uu_ 4         RRR4       V P                  S^ ,          4       V P                  S^,          R4       R#   + '       g   i     LC; i)Ftimeoutg}Ô%ITc                     < \         P                  ! 4       p SP                  SP                  R R7      4       \         P                  ! 4       pSP                  W,
          4       R# )      ?r   N)r   	monotonicr   rj   )t1t2ra   resultss     r   r   %BaseLockTests.test_timeout.<locals>.f   s@    !BNN4<<<45!BNN27#r   Nr   i)r_   r   
ValueErrorrj   OverflowErrorr   rr   r   r   rw   rR   r   r   rU   )r   r   r   r   ra   r   s   &   @@r   test_timeoutBaseLockTests.test_timeout   s   }}*dllE1=*dllDA-uE-{QO[)^^Q/0^^#	$
 1a[[ $71:s+ [s   F		F	c                ~    V P                  4       p\        P                  ! V4      pV P                  V! 4       4       R # r   )r_   weakrefrefassertIsNotNoner   ra   r   s   &  r   test_weakref_exists!BaseLockTests.test_weakref_exists   s+    }}kk$SU#r   c                    V P                  4       p\        P                  ! V4      p?\        P                  ! 4        V P                  V! 4       4       R # r   )r_   r   r   gccollectassertIsNoner   s   &  r   test_weakref_deleted"BaseLockTests.test_weakref_deleted  s7    }}kk$


#% r   r)   N)r;   r<   r=   r>   r?   r\   rb   rg   rk   rn   rs   rx   r   r   r   r   r   r   r   r@   rA   rB   s   @r   rX   rX   p   sU     /


	1$:,6$
! !r   rX   c                   F   a  ] tR tRt o RtR tR tR t]R 4       t	Rt
V tR# )		LockTestsi	  zb
Tests for non-recursive, weak locks
(which can be acquired and released from different threads).
c                0  aa V P                  4       o. oVV3R  lp\        P                  ! 4       ;_uu_ 4        \        VR4       V P	                  S^4       SP                  4        V P	                  S^4       RRR4       R#   + '       g   i     R# ; i)c                     < S P                  4        SP                  R 4       S P                  4        SP                  R 4       R # r   rj   r   )ra   r[   s   r   r   #LockTests.test_reacquire.<locals>.f  s-    LLNLLLLNLLr   Nr)   )r_   r   r*   r   r\   rr   r   r   ra   r[   s   & @@r   test_reacquireLockTests.test_reacquire  si    }}	 //11Q#OOE1% LLNOOE1% 2111s   ABB	c                   a V P                  4       oSP                  4        V3R  lp\        V^4      ;_uu_ 4         RRR4       SP                  4        SP                  4        R#   + '       g   i     L2; i)c                  (   < S P                  4        R # r   )rr   r   s   r   r   *LockTests.test_different_thread.<locals>.f&      LLNr   N)r_   rj   r   rr   r   s   & @r   test_different_threadLockTests.test_different_thread"  sI    }}	1a[[  [s   A((A8	c                (   V P                  4       pVP                  4        V P                  VP                  R R7      4       VP                  4        V P                  VP	                  4       4       V P                  VP                  RR7      4       R# )r   r   F)blockingN)r_   rj   r   rr   lockedrw   r`   s   & r   test_state_after_timeout"LockTests.test_state_after_timeout-  se     }}d34'e45r   c                    R  pV P                  4       pVP                  4        V! V4       V P                  4       pVP                  4        VP                  4        V! V4       R# )c                 F    V P                  4        V P                  4        R # r   r   r   s   &r   use_lock/LockTests.test_at_fork_reinit.<locals>.use_lock9  s     LLNLLNr   N)r_   _at_fork_reinitrj   )r   r   ra   lock2s   &   r   test_at_fork_reinitLockTests.test_at_fork_reinit7  sP    	 }} r   r)   N)r;   r<   r=   r>   r?   r   r   r   requires_forkr   r@   rA   rB   s   @r   r   r   	  s-     &(	6  r   r   c                   Z   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tRtV tR# )
RLockTestsiK  z
Tests for recursive locks.
c                  aa V P                  4       oV P                  R \        S4      4       V P                  R\        S4      4       SP                  4        SP                  4        V P                  R\        S4      4       V P                  R\        S4      4       . oVV3R lp\	        V^4      ;_uu_ 4         RRR4       V P                  RS^ ,          4       V P                  RS^ ,          4       R#   + '       g   i     LD; i)zcount=0z	<unlockedzcount=2z<lockedc                  <   < SP                  \        S 4      4       R # r   )r   rf   r}   s   r   	call_repr-RLockTests.test_repr_count.<locals>.call_repr\  s    MM$t*%r   N)r_   assertInrf   rj   r   )r   r   ra   r~   s   & @@r   test_repr_countRLockTests.test_repr_countO  s     }}id,k4:.id,id,	&9a   !i+i+ ! s   <C::D
	c                    V P                  4       pVP                  4        VP                  4        VP                  4        VP                  4        VP                  4        VP                  4        R # r   rq   r`   s   & r   r   RLockTests.test_reacquirec  sC    }}r   c                f   V P                  4       pV P                  \        VP                  4       VP	                  4        VP	                  4        VP                  4        VP	                  4        VP                  4        VP                  4        V P                  \        VP                  4       R # r   )r_   r   RuntimeErrorrr   rj   r`   s   & r   test_release_unacquired"RLockTests.test_release_unacquiredl  sk    }},5,5r   c                   V P                  4       pV P                  VP                  4       4       VP                  4        V P	                  VP                  4       4       VP                  4        V P	                  VP                  4       4       VP                  4        V P	                  VP                  4       4       VP                  4        V P                  VP                  4       4       R # r   )r_   r   r   rj   rw   rr   r`   s   & r   test_lockedRLockTests.test_lockedx  s    }}'&&&'r   c                z  aa . oV P                  4       oV P                  SP                  4       4       VV3R  lp\        V^4      ;_uu_ 4         RRR4       V P	                  SP                  4       4       V P                  S^ ,          4       V P	                  S^,          4       R#   + '       g   i     La; i)c                     < S P                  SP                  4       4       SP                  4        S P                  SP                  4       4       R # r   )r   r   rj   )r~   rlocks   r   rj   5RLockTests.test_locked_with_2threads.<locals>.acquire  s0    MM%,,.)MMOMM%,,.)r   N)r_   r   r   r   rw   )r   rj   r~   r   s   & @@r   test_locked_with_2threads$RLockTests.test_locked_with_2threads  s     (	*
 7A '#q	"	 s   B**B:	c                f   V P                  4       pV P                  \        VP                  4       VP	                  4        VP	                  4        VP                  4        VP	                  4        VP                  4        VP                  4        V P                  \        VP                  4       R # r   )r_   r   r   _release_saverj   rr   r`   s   & r   test_release_save_unacquired'RLockTests.test_release_save_unacquired  so    }},(:(:;,(:(:;r   c                  a aa S P                  4       oS P                  ^ SP                  4       4       SP                  4        S P                  ^SP                  4       4       SP                  4        SP                  4        S P                  ^SP                  4       4       SP	                  4        S P                  ^SP                  4       4       SP	                  4        SP	                  4        S P                  ^ SP                  4       4       . oVVV 3R lp\
        P                  ! 4       ;_uu_ 4        \        VR4       S P                  S^4       S P                  ^ SP                  4       4       SP                  R4       S P                  S^4       S P                  ^ SP                  4       4       RRR4       R#   + '       g   i     R# ; i)    c                     < S P                  4        SP                  R 4       SP                  S^4       S P                  4        SP                  R 4       R # r   )rj   r   r\   rr   )ra   r[   r   s   r   r   *RLockTests.test_recursion_count.<locals>.f  s;    LLNLLOOE1%LLNLLr   Nr)   )
r_   rZ   _recursion_countrj   rr   r   r*   r   r\   r   r   s   f @@r   test_recursion_countRLockTests.test_recursion_count  sQ   }}D1134D1134D1134D1134D1134	 //11Q#OOE1%Q 5 5 78 LLOOE1%Q 5 5 78 2111s   ;BGG	c                &  a V P                  4       oV3R  lp\        V^R4      ;_uu_ 4       p V P                  \        SP                  4       VP                  4         RRR4       R#   TP                  4        i ; i  + '       g   i     R# ; i)c                  (   < S P                  4        R # r   )rj   r   s   r   r   +RLockTests.test_different_thread.<locals>.f  r   r   TN)r_   r   r   r   rr   r9   )r   r   r   ra   s   &  @r   r    RLockTests.test_different_thread  sk    }}	 1a%"!!,=!	  !	 s"   A? A*A?*A<<A??B	c                  aa V P                  4       oV P                  SP                  4       4       SP                  4        V P	                  SP                  4       4       SP                  4        V P	                  SP                  4       4       . oVV3R  lp\        V^4      ;_uu_ 4         RRR4       V P                  S^ ,          4       SP                  4        V P	                  SP                  4       4       SP                  4        V P                  SP                  4       4       R#   + '       g   i     L; i)c                  F   < SP                  S P                  4       4       R # r   )r   	_is_ownedr}   s   r   r   $RLockTests.test__is_owned.<locals>.f  s    MM$..*+r   N)r_   r   r  rj   rw   r   rr   r   s   & @@r   test__is_ownedRLockTests.test__is_owned  s    }})*()()	,1a[[ #())* [s   -D//D?	r)   N)r;   r<   r=   r>   r?   r   r   r   r   r   r   r   r   r  r@   rA   rB   s   @r   r   r   K  s=     ,(
6
(#$
<!9F
"+ +r   r   c                   X   a  ] tR tRt o RtR tR tR tR tR t	]
R 4       tR	 tR
tV tR# )
EventTestsi  z
Tests for Event objects.
c                   V P                  4       pV P                  VP                  4       4       VP                  4        V P	                  VP                  4       4       VP                  4        V P	                  VP                  4       4       VP                  4        V P                  VP                  4       4       VP                  4        V P                  VP                  4       4       R # r   )	eventtyper   is_setsetrw   clearr   evts   & r   test_is_setEventTests.test_is_set  s    nn&	

%	

%		&		&r   c                Z  aaa ^p. o. oVVV3R lp\        W24      ;_uu_ 4        \        V4       V P                  \        S4      ^ 4       SP	                  4        RRR4       V P                  SR.V,          4       V P                  SR.V,          4       R#   + '       g   i     LF; i)   c                     < SP                  S P                  4       4       SP                  S P                  4       4       R # r   )r   wait)r  results1results2s   r   r   #EventTests._check_notify.<locals>.f  s'    OOCHHJ'OOCHHJ'r   NT)r   r   rZ   r-   r
  )r   r  r   r   r  r  s   &f  @@r   _check_notifyEventTests._check_notify  s    	( 1[[ #S]A. GGI  	D6A:.D6A:. [s   7BB*	c                    V P                  4       pV P                  V4       VP                  4        VP                  4        V P                  V4       R # r   )r  r  r
  r  r  s   & r   test_notifyEventTests.test_notify	  s<    nn3			3r   c                ,  aaa V P                  4       o. o. o^pVVV3R lp\        W!4      ;_uu_ 4         RRR4       V P                  SR.V,          4       S F(  w  r4V P                  V4       V P	                  VR4       K*  	  . o. oSP                  4        \        W!4      ;_uu_ 4         RRR4       V P                  SR.V,          4       S F  w  r4V P                  V4       K  	  R#   + '       g   i     L; i  + '       g   i     L[; i)r  c                     < SP                  SP                  R 4      4       \        P                  ! 4       p SP                  R4      p\        P                  ! 4       pSP                  WV ,
          34       R# )g        r   N)r   r  r   r   )r   rr   r  r  r  s      r   r   "EventTests.test_timeout.<locals>.f  sN    OOCHHSM*!BA!BOOQRL)r   NFr   T)r  r   rZ   r   rU   r
  rw   )r   r   r   r  dtr  r  r  s   &    @@@r   r   EventTests.test_timeout  s    nn	* 1[[  	E7Q;/EAQr3' 
 	1[[  	D6A:.EAOOA ! [ [s   C0.D0D 	D	c                (  aa V P                  4       o. oVV3R  lp^p\        W4      ;_uu_ 4        \        V4       SP                  4        SP	                  4        RRR4       V P                  SR.V,          4       R#   + '       g   i     L,; i)c                  d   < SP                  S P                  \        P                  4      4       R # r   )r   r  r   LONG_TIMEOUT)eventr   s   r   r   (EventTests.test_set_and_clear.<locals>.f5  s    NN5::g&:&:;<r   NT)r  r   r   r
  r  rZ   )r   r   r   r%  r   s   &  @@r   test_set_and_clearEventTests.test_set_and_clear0  sl      	= 1[[ # IIKKKM  	4&1*- [s   ,BB	c                   V P                  4       pVP                  ;_uu_ 4        V P                  VP                  P                  R 4      4       RRR4       VP	                  4        VP                  ;_uu_ 4        V P                  VP                  P                  R 4      4       RRR4       R#   + '       g   i     Li; i  + '       g   i     R# ; irv   )r  _condr   rj   r   r  s   & r   r   EventTests.test_at_fork_reinitC  s     nnYYYSYY..u56 YYYSYY..u56 Y Y YYs   +B1<+C1C	C	c                    V P                  4       pV P                  \        V4      R 4       VP                  4        V P                  \        V4      R4       R# )z<\w+\.Event at .*: unset>z<\w+\.Event at .*: set>N)r  re   rf   r
  r  s   & r   rg   EventTests.test_reprM  sA    nnc$@A	c$>?r   r)   N)r;   r<   r=   r>   r?   r  r  r  r   r'  r   r   rg   r@   rA   rB   s   @r   r  r    sC     
'/( >.& 7 7@ @r   r  c                   T   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tRtV tR# )ConditionTestsiT  z 
Tests for condition variables.
c                   V P                  4       pVP                  4        VP                  4        VP                  4        VP                  4        \        P                  ! 4       pV P                  V4      pVP                  4        V P                  VP                  R 4      4       VP                  4        V P                  VP                  R 4      4       V P                  VP                  R 4      4       VP                  4        V;_uu_ 4        V P                  VP                  R 4      4       RRR4       R#   + '       g   i     R# ; irv   )condtyperj   rr   r   Lockr   rw   )r   condra   s   &  r   test_acquireConditionTests.test_acquireY  s    }} 	~~}}T"e,-U+,e,-TT\\%01 TTTs   !D<<E	c                f    V P                  4       pV P                  \        VP                  4       R # r   )r1  r   r   r  r   r3  s   & r   test_unacquired_wait#ConditionTests.test_unacquired_waitl  s!    }},		2r   c                f    V P                  4       pV P                  \        VP                  4       R # r   )r1  r   r   notifyr7  s   & r   test_unacquired_notify%ConditionTests.test_unacquired_notifyp  s!    }},4r   c                  aaaa	a
 . o. o	. o
^ oVVVV	V
3R lp^p\        W#4      ;_uu_ 4        \        P                  ! \        P                  4       F  p\	        S4      V8  g   K   M	  SP                  4        V P                  S	. 4       ^pSP                  4        SP                  V4       \        V4       ^oSP                  4        \        P                  ! \        P                  4       F  p\	        S	4      V8  g   K   M	  V P                  S	R.V,          4       V P                  S
. 4       \        P                  ! \        P                  4       F  p\	        S4      V8  g   K   M	  SP                  4        SP                  ^4       \        V4       ^oSP                  4        \        P                  ! \        P                  4       F+  p\	        S	4      \	        S
4      ,           W5,           8  g   K+   M	  W5,
          pV P                  S	R.V,          R.V,          ,           4       V P                  S
R.V,          4       \        P                  ! \        P                  4       F  p\	        S4      V8  g   K   M	  SP                  4        SP                  4        \        V4       ^oSP                  4        \        P                  ! \        P                  4       F  p\	        S
4      V8  g   K   M	  V P                  S	R.V,          R.V,          ,           4       V P                  S
R.V,          R.V,          ,           4       RRR4       R#   + '       g   i     R# ; i)r   c                  X  < SP                  4        SP                  S4       SP                  4       p SP                  4        SP                  V S34       SP                  4        SP                  S4       SP                  4       p SP                  4        SP                  V S34       R # r   )rj   r   r  rr   )r~   r3  	phase_numreadyr  r  s    r   r   'ConditionTests._check_notify.<locals>.f  sw    LLNLL#YY[FLLNOOVY/0LLNLL#YY[FLLNOOVY/0r   N)T   )T   )T   )r   r   r!   r"   r-   r  rZ   rj   r;  r   rr   
notify_all)r   r3  r   r   r%   count1count2r@  rA  r  r  s   &f     @@@@r   r  ConditionTests._check_notifyt  s    		1 	1 1[[ ++G,A,ABu:? C KKMXr* FLLNKK ( ILLN++G,A,ABx=F* C X	{V';<Xr* ++G,A,ABu:' C
 LLNKKN # ILLN++G,A,ABx=3x=0QZ@ C ZFX	{V';ykF>R'RSX	{V';< ++G,A,ABu:? C
 LLNOO # ILLN++G,A,ABx=A% C X	{V';ykF>R'RSX	{V';ykF>R'RSA [[[s5   5M"'BM"A$M"/BM" BM"A5M"AM""M3	c                j    V P                  4       pV P                  V4       V P                  V4       R # r   )r1  r  r7  s   & r   r  ConditionTests.test_notify  s)    }}4 4 r   c                :  aaa V P                  4       oR o. oVVV3R lp^p\        W4      ;_uu_ 4         RRR4       V P                  \        S4      V4       S F(  w  r4V P	                  VS4       V P                  V4       K*  	  R#   + '       g   i     L[; i)r   c                     < SP                  4        \        P                  ! 4       p SP                  S4      p\        P                  ! 4       pSP	                  4        SP                  W ,
          V34       R # r   )rj   r   r   r  rr   r   )r   r~   r   r3  r   r   s      r   r   &ConditionTests.test_timeout.<locals>.f  sN    LLN!BYYw'F!BLLNNNBGV,-r   N)r1  r   rZ   r-   rU   r   )r   r   r   r   r~   r3  r   r   s   &    @@@r   r   ConditionTests.test_timeout  s}    }}	. 1[[ Wq)!JBr7+ V$ "	 [s   B

B	c           
     r  a aa S P                  4       o^ oVV V3R lp\        V^4      ;_uu_ 4        \        ^4       FE  p\        P                  ! R4       S;_uu_ 4        S^,          oSP                  4        RRR4       KG  	  RRR4       R#   + '       g   i     Kd  ; i  + '       g   i     R# ; i)r   c                     < S;_uu_ 4        SP                  V3R  l4      p SP                  V 4       SP                  S^4       RRR4       R#   + '       g   i     R# ; i)c                     < S ^8H  #    r)   states   r   <lambda>8ConditionTests.test_waitfor.<locals>.f.<locals>.<lambda>  s	    uzr   N)wait_forrw   rZ   )r~   r3  r   rV  s    r   r   &ConditionTests.test_waitfor.<locals>.f  s?    '9:'  * s   9AA 	r   N)r1  r   r,   r   r	   r;  )r   r   ir3  rV  s   f  @@r   test_waitforConditionTests.test_waitfor  sx    }}	+ 1a[[1X

5!TQJEKKM T  [ TT [[s#   /B%!B;B%B"	B%%B6	c           
       a aaa S P                  4       o^ o. oVV VV3R lp\        V^4      ;_uu_ 4        \        ^4       FE  p\        P                  ! R4       S;_uu_ 4        S^,          oSP                  4        RRR4       KG  	  RRR4       S P                  \        S4      ^4       R#   + '       g   i     K  ; i  + '       g   i     LA; i)r   c                  N  < S;_uu_ 4        \         P                  ! 4       p SP                  V3R  lRR7      p\         P                  ! 4       V ,
          p SP                  V4       SP	                  V R4       SP                  R4       RRR4       R#   + '       g   i     R# ; i)c                     < S ^8H  # rS  r)   rU  s   r   rW  @ConditionTests.test_waitfor_timeout.<locals>.f.<locals>.<lambda>  s	    qr   皙?r   N)r   r   rY  r   rU   r   )r   r~   r3  r   rV  successs     r   r   .ConditionTests.test_waitfor_timeout.<locals>.f
  sn    ^^%'8#F^^%*  (""2s+t$ s   A=BB$	r   N)r1  r   r,   r   r	   r;  rZ   r-   )r   r   r[  r3  rV  rc  s   f  @@@r   test_waitfor_timeout#ConditionTests.test_waitfor_timeout  s    }}	% 	% 1a[[1X

5!TQJEKKM T   	Wq)	 TT	 [s#   /C%B0?C0C;	CC	r)   N)r;   r<   r=   r>   r?   r4  r8  r<  r  r  r   r\  re  r@   rA   rB   s   @r   r/  r/  T  s:     2&35`TD!%4" * *r   r/  c                   `   a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tRtV tR# )BaseSemaphoreTestsi  z:
Common tests for {bounded, unbounded} semaphore objects.
c                    V P                  \        V P                  RR7       V P                  \        V P                  \        P                  ) R7       R# )rC  )valueN)r   r   semtypesysmaxsizer8   s   &r   rb   #BaseSemaphoreTests.test_constructor#  s:    *dllB?*dllS[[LIr   c                
   V P                  ^4      pVP                  4        VP                  4        V P                  ^4      pVP                  4        VP                  4        VP                  4        VP                  4        R# rC  N)rl  rj   rr   r   sems   & r   r4  BaseSemaphoreTests.test_acquire'  sR    ll1oll1or   c                H    V P                  4       pVP                  4        ?R # r   )rl  rj   rr  s   & r   rn   'BaseSemaphoreTests.test_acquire_destroy1  s    llnr   c                  a
aaaa ^pV P                  V4      oSP                  4        . o. o. o^ o
V
VVVV3R lpVV3R lp^
p\        W$4      ;_uu_ 4        V^,
          pV! V4       V P                  SS,           ^ .V,          4       ^o
\	        V4       F  pSP                  4        K  	  TpV! WW,           4       V P                  \        SS,           4      ^ .V,          ^.V,          ,           4       ^o
V^,
          p\	        V4       F  pSP                  4        K  	  V! WW,           V,           4       V P                  \        SS,           4      ^ .V,          ^.V,          ,           ^.V,          ,           4       V P                  SP                  R4      4       ^p	SP                  4        RRR4       V P                  SR.XX,           X,           X	,           ,          4       R#   + '       g   i     LA; i)   c                     < SP                  SP                  4       4       SP                  S 4       SP                  SP                  4       4       SP                  S 4       R # r   r|   )r@  r  r  rs  sem_resultss   r   r   7BaseSemaphoreTests.test_acquire_contended.<locals>.func@  sC    s{{}-OOI&s{{}-OOI&r   c                    < \         P                  ! \         P                  4       F&  p\        S4      \        S4      ,           V 8  g   K%   R # 	  R # r   r   r!   r"   r-   countr%   r  r  s   & r   
wait_count=BaseSemaphoreTests.test_acquire_contended.<locals>.wait_countG  7    ++G,A,ABx=3x=0E9 Cr   FNT)rl  rj   r   rZ   r,   rr   sortedr   )r   	sem_valuer   r  r   rG  r[  rH  count3count4r@  r  r  rs  rz  s   &         @@@@@r   r   )BaseSemaphoreTests.test_acquire_contended6  s   	ll9%		' 	'	
 4^^]FvX01#,? I9% &Fv'VHx$78S6\QC&L8: I!mF6] #v/0VHx$78S6\QC&L8A3<GI S[[/0 FKKM9 < 	6F?V#;f#DE	G= ^s   EG,,G<	c                P  aaa	a
 ^pV P                  V4      o
S
P                  4        . o. o	^ oVVV	V
3R lpVV	3R lp\        V^
4      ;_uu_ 4        V^,
          pV! V4       V P                  SS	,           ^ .V,          4       ^oTpS
P	                  V4       V! WE,           4       V P                  \        SS	,           4      ^ .V,          ^.V,          ,           4       ^oV^,
          pS
P	                  V4       V! WE,           V,           4       V P                  \        SS	,           4      ^ .V,          ^.V,          ,           ^.V,          ,           4       V P                  S
P                  R4      4       S
P	                  4        RRR4       R#   + '       g   i     R# ; i)rx  c                     < SP                  4        SP                  S 4       SP                  4        SP                  S 4       R # r   r   )r@  r  r  rs  s   r   r   2BaseSemaphoreTests.test_multirelease.<locals>.funcv  s-    KKMOOI&KKMOOI&r   c                    < \         P                  ! \         P                  4       F&  p\        S4      \        S4      ,           V 8  g   K%   R # 	  R # r   r}  r~  s   & r   r  8BaseSemaphoreTests.test_multirelease.<locals>.wait_count}  r  r   FN)rl  rj   r   rZ   rr   r  r   )r   r  r   r  rG  rH  r  r@  r  r  rs  s   &      @@@@r   test_multirelease$BaseSemaphoreTests.test_multireleasen  s[   	ll9%		' 	'	
 4__]FvX01#,? IFKKv'VHx$78S6\QC&L8: I]FKKv/0VHx$78S6\QC&L8A3<GI S[[/0 KKM3 ___s   D8FF%	c                H   V P                  ^4      pV P                  VP                  R4      4       V P                  VP                  R4      4       V P                  VP                  R4      4       VP	                  4        V P                  VP                  R4      4       R# )rD  FN)rl  rw   rj   r   rr   rr  s   & r   rx   #BaseSemaphoreTests.test_try_acquire  sn    ll1oE*+E*+U+,E*+r   c                $  aa V P                  ^4      oSP                  4        . oVV3R lp\        V^4      ;_uu_ 4         RRR4       V P                  \	        S4      R.^,          R.^,          ,           4       R#   + '       g   i     LD; i)rT  c                     < S P                  SP                  R 4      4       S P                  SP                  R 4      4       R# rv   r|   )r   rs  s   r   r   8BaseSemaphoreTests.test_try_acquire_contended.<locals>.f  s-    NN3;;u-.NN3;;u-.r   NFT)rl  rj   r   rZ   r  )r   r   r   rs  s   & @@r   r   -BaseSemaphoreTests.test_try_acquire_contended  sg    ll1o	/ 1a[[ 
 	5'A+!*CE [s   A??B	c                ^   V P                  ^4      pV P                  \        VP                  RRR7       V P	                  VP                  RR7      4       V P	                  VP                  RR7      4       V P                  VP                  RR7      4       VP                  4        V P	                  VP                  RR7      4       \        P                  ! 4       pV P                  VP                  RR7      4       \        P                  ! 4       V,
          pV P                  VR4       R# )rD  Fg      ?r   g{Gzt?r   N)
rl  r   r   rj   rw   r   rr   r   r   rU   )r   rs  tr   s   &   r   test_acquire_timeout'BaseSemaphoreTests.test_acquire_timeout  s    ll1o*ckk5#FE23E23U34E23NNS12^^!2s#r   c                "  a V P                  4       oSP                  4        V3R  lp\        V^4      ;_uu_ 4       p\        ^4       V P	                  VP
                  4       SP                  4        RRR4       R#   + '       g   i     R# ; i)c                  H   < S P                  4        S P                  4        R # r   r   )rs  s   r   r   0BaseSemaphoreTests.test_default_value.<locals>.f  s    KKMKKMr   N)rl  rj   r   r   r   r   rr   )r   r   r   rs  s   &  @r   test_default_value%BaseSemaphoreTests.test_default_value  s\    lln	 1a[[E #U^^, KKM [[[s   7A==B	c                B  a a S P                  ^4      oRV V3R llpV! 4        S P                  SP                  R4      4       SP                  4        S P	                  \
        V\
        4       S P                  SP                  R4      4       SP                  4        R# )rD  Nc           	      X  < S;_uu_ 4        SP                  SP                  R 4      4       SP                  4        S;_uu_ 4        SP                  SP                  R 4      4       V '       d   V h RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; irv   )rw   rj   rr   r   )r   r   rs  s   &r   _with+BaseSemaphoreTests.test_with.<locals>._with  sm    E 23S$$S[[%78!	    S s#   ;B+B	3BBBB)	Fr   )rl  rw   rj   rr   r   r   )r   r  rs  s   f @r   r   BaseSemaphoreTests.test_with  so    ll1o	" 	" 	E*+)UI6E*+r   r)   N)r;   r<   r=   r>   r?   rb   r4  rn   r   r  rx   r   r  r  r   r@   rA   rB   s   @r   rh  rh    sF     J
6Gp-^,F$  r   rh  c                   0   a  ] tR tRt o RtR tR tRtV tR# )SemaphoreTestsi  z!
Tests for unbounded semaphores.
c                    V P                  ^4      pVP                  4        VP                  4        VP                  4        VP                  4        R# rq  )rl  rr   rj   rr  s   & r   r   &SemaphoreTests.test_release_unacquired  s3    ll1or   c                *   V P                  ^4      pV P                  \        V4      R4       VP                  4        V P                  \        V4      R4       VP	                  4        VP	                  4        V P                  \        V4      R4       R# )rE  z<\w+\.Semaphore at .*: value=3>z<\w+\.Semaphore at .*: value=2>z<\w+\.Semaphore at .*: value=4>N)rl  re   rf   rj   rr   rr  s   & r   rg   SemaphoreTests.test_repr  si    ll1oc$FGc$FGc$FGr   r)   N	r;   r<   r=   r>   r?   r   rg   r@   rA   rB   s   @r   r  r    s     H Hr   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )BoundedSemaphoreTestsi  z
Tests for bounded semaphores.
c                    V P                  4       pV P                  \        VP                  4       VP	                  4        VP                  4        V P                  \        VP                  4       R # r   )rl  r   r   rr   rj   rr  s   & r   r   -BoundedSemaphoreTests.test_release_unacquired  sG    lln*ckk2*ckk2r   c                    V P                  ^4      pV P                  \        V4      R4       VP                  4        V P                  \        V4      R4       R# )rE  z(<\w+\.BoundedSemaphore at .*: value=3/3>z(<\w+\.BoundedSemaphore at .*: value=2/3>N)rl  re   rf   rj   rr  s   & r   rg   BoundedSemaphoreTests.test_repr  sB    ll1oc$OPc$OPr   r)   Nr  rB   s   @r   r  r    s     3Q Qr   r  c                      a  ] tR tRt o Rt^tRtR tR tR t	R t
R tRR	 ltR
 tR tR tR tR tR tR tR tR tR tRtV tR# )BarrierTestsi  z
Tests for Barrier objects.
g       @c                ^    V P                  V P                  V P                  R 7      V n        R# )r   N)barriertyper   defaultTimeoutbarrierr8   s   &r   rI   BarrierTests.setUp  s#    ''8K8K'Lr   c                :    V P                   P                  4        R # r   )r  abortr8   s   &r   rN   BarrierTests.tearDown  s    r   c                |    \        WP                  4      ;_uu_ 4         R R R 4       R #   + '       g   i     R # ; ir   )r   r   r   r   s   &&r   run_threadsBarrierTests.run_threads  s#    1ff s   *;	c                   V P                   P                  pV P                  W0P                  4       \	        V4       F  pV^ ,          P                  R4       V P                  \        V^,          4      WC,          4       V P                   P                  4        V^,          P                  R4       V P                  \        V^ ,          4      V^,           V,          4       V P                   P                  4        K  	  V P                  V P                   P                  ^ 4       V P                  V P                   P                  4       R# )r   TN)r  partiesrZ   r   r,   r   r-   r  	n_waitingr   broken)r   r   nmr[  s   &&&  r   	multipassBarrierTests.multipass  s    LL  FF#qAAJd#S_ae4LLAJd#S_q1uk:LL  	//3,,-r   c                    V P                  \        V P                  ^ R7       V P                  \        V P                  RR7       R# )r   )r  Nrk  )r   r   r  r8   s   &r   rb   BarrierTests.test_constructor*  s8    *d&6&6B*d&6&6Cr   c                F   a aa . . .oVVV 3R lpS P                  V4       R# )z+
Test that a barrier is passed in lockstep
c                  ,   < SP                  SS 4       R # r   )r  )passesr   r   s   r   r   $BarrierTests.test_barrier.<locals>.f3  s    NN7F+r   Nr  )r   r  r   r   s   ff @r   test_barrierBarrierTests.test_barrier.  s!     b'	,r   c                $    V P                  ^
4      # )z3
Test that a barrier works for 10 consecutive runs
)r  r8   s   &r   test_barrier_10BarrierTests.test_barrier_107  s       $$r   c                   a a . oVV 3R lpS P                  V4       S P                  \        S4      \        \        S P                  4      4      4       R# )z)
test the return value from barrier.wait
c                  ^   < SP                   P                  4       p SP                  V 4       R # r   )r  r  r   )r  r   r   s    r   r   (BarrierTests.test_wait_return.<locals>.fB  s!    !!#ANN1r   N)r  rZ   sumr,   r   )r   r   r   s   f @r   test_wait_returnBarrierTests.test_wait_return=  s@     	 	Ws5='9:r   c                   a aa . oV3R lpS P                  S P                  V4      oVVV 3R lpS P                  V4       R# )z
Test the 'action' callback
c                  *   < S P                  R 4       R# r7   )r   )r   s   r   action(BarrierTests.test_action.<locals>.actionN  s    NN4 r   c                  ^   < S P                  4        SP                  \        S4      ^4       R# rq  )r  rZ   r-   )r  r   r   s   r   r   #BarrierTests.test_action.<locals>.fQ  s     LLNS\1-r   N)r  r   r  )r   r  r   r  r   s   f  @@r   test_actionBarrierTests.test_actionI  s:     	!""46662	. 	r   c                  a aa . o. oVVV 3R lpS P                  V4       S P                  \        S4      ^ 4       S P                  \        S4      S P                  ^,
          4       S P	                  S P
                  P                  4       R# )z;
Test that an abort will put the barrier in a broken state
c                  x  <  SP                   P                  4       p V SP                  ^,          8X  d   \        hSP                   P                  4        SP	                  R4       R#   \
        P                   d    SP	                  R4        R# \         d    SP                   P                  4         R# i ; irD  TN)r  r  r   r   r   r   BrokenBarrierErrorr  )r[  r  r  r   s    r   r   "BarrierTests.test_abort.<locals>.f]  s    
LL%%'	>&&!!#%// &% ""$s"   1A( 1A( (&B9B9B98B9N)r  rZ   r-   r   rw   r  r  )r   r   r  r  s   f @@r   
test_abortBarrierTests.test_abortW  sj     	 	X*Xq1++,r   c                &  a aaa . o. o. oVVVV 3R lpS P                  V4       S P                  \        S4      ^ 4       S P                  \        S4      S P                  ^,
          4       S P                  \        S4      S P                  4       R# )z<
Test that a 'reset' on a barrier frees the waiting threads
c                  Z  < SP                   P                  4       p V SP                  ^,          8X  du   \        P                  ! \        P
                  4       F1  pSP                   P                  SP                  ^,
          8  g   K1   M	  SP                   P                  4        M, SP                   P                  4        SP                  R4       SP                   P                  4        SP                  R4       R#   \        P                   d    SP                  R4        LUi ; ir  )r  r  r   r   r!   r"   r  resetr   r   r  )r[  r%   r  r  results3r   s     r   r   "BarrierTests.test_reset.<locals>.fv  s    !!#ADFFAI~ //0E0EFA||--$&&1*= G ""$*LL%%'OOD) LLOOD!	 !33 *OOD)*s   )+D &D*)D*N)r  rZ   r-   r   )r   r   r  r  r  s   f @@@r   
test_resetBarrierTests.test_reseto  sv     	" 	"$ 	X*Xq1X/r   c                `  a aaaa . o. o. oS P                  S P                  4      oVVVVV 3R lpS P                  V4       S P                  \	        S4      ^ 4       S P                  \	        S4      S P                  ^,
          4       S P                  \	        S4      S P                  4       R# )z6
Test that a barrier can be reset after being broken.
c                  j  <  SP                   P                  4       p V SP                  ^,          8X  d   \        hSP                   P                  4        SP	                  R4       SP                  4       SP                  ^,          8X  d   SP                   P                  4        SP                  4        SP                   P                  4        SP	                  R4       R#   \
        P                   d    SP	                  R4        L\         d    SP                   P                  4         Li ; ir  )	r  r  r   r   r   r   r  r  r  )r[  barrier2r  r  r  r   s    r   r   ,BarrierTests.test_abort_and_reset.<locals>.f  s    
LL%%'	>&&!!#% }}$&&!)+""$MMOLLOOD! // &% ""$s"   1C# 1C# #&D2D2D21D2N)r  r   r  rZ   r-   )r   r   r  r  r  r  s   f @@@@r   test_abort_and_reset!BarrierTests.test_abort_and_reset  s     ##DFF+	" 	"* 	X*Xq1X/r   c                6   a  V 3R lpS P                  V4       R# )z
Test wait(timeout)
c                  F  < SP                   P                  4       p V SP                  ^,          8X  d(   \        P                  ! SP
                  ^,          4       SP                  \        P                  SP                   P                  SP
                  ^,          4       R# )rD  N)	r  r  r   r   r	   r  r   r   r  )r[  r   s    r   r   $BarrierTests.test_timeout.<locals>.f  sm    !!#ADFFaK

4..23i::"ll//1D1Dq1HJr   Nr  r  s   f r   r   BarrierTests.test_timeout  s    	J 	r   c                (  a a RpS P                  ^VR7      oVV 3R lp\        P                  ! 4       p\        V^4      ;_uu_ 4         RRR4       \        P                  ! 4       V,
          pS P	                  WA4       R#   + '       g   i     L?; i)z$
Test the barrier's default timeout
rb  r   c                  \   < SP                  \        P                  S P                  4       R # r   )r   r   r  r  )r  r   s   r   r   ,BarrierTests.test_default_timeout.<locals>.f  s     i::%ll,r   N)r  r   r   r   rQ   )r   r   r   
start_timer   r  s   f    @r   test_default_timeout!BarrierTests.test_default_timeout  sl     ""1g"6	, ^^%
1a[[ ^^
*, [s   BB	c                h    V P                  ^4      pVP                  4        VP                  4        R# rq  )r  r  )r   bs   & r   test_single_threadBarrierTests.test_single_thread  s$    Q		r   c                R  aa V P                  ^4      o\        P                  oV P                  \	        S4      R4       VV3R lp^p\        W4      ;_uu_ 4        \        P                  ! \        P                  4       F  pSP                  V8  g   K   M	  V P                  \	        S4      R4       SP                  S4       RRR4       V P                  \	        S4      R4       SP                  4        V P                  \	        S4      R4       R#   + '       g   i     LX; i)rE  z!<\w+\.Barrier at .*: waiters=0/3>c                  *   < S P                  S4       R # r   )r  )r  r   s   r   r   !BarrierTests.test_repr.<locals>.f  s    LL!r   z!<\w+\.Barrier at .*: waiters=2/3>Nz<\w+\.Barrier at .*: broken>)r  r   r$  re   rf   r   r!   r"   r  r  r  )r   r   r   r%   r  r   s   &   @@r   rg   BarrierTests.test_repr  s    ""1%&&g(LM	" 1[[++G,A,AB$$) C T']AC LL!  	g=	? 	g8	:! [s   6D0DD&	)r  N)rC  )r;   r<   r=   r>   r?   r   r  rI   rN   r  r  rb   r  r  r  r  r  r  r  r   r  r   rg   r@   rA   rB   s   @r   r  r    sn      	
ANM.D%
;-00> 0D- 
: :r   r  )r?   r   rm  r   _threadr   r   r   unittestr   testr   test.supportr   
skipUnlesshas_fork_supportr   r   objectr   TestCaserE   rX   r   r   r  r/  rh  r  r  r  r)   r   r   <module>r     s    
 
  1     ) ##G$<$<%CD
 @F @F18$$ 1"V!L V!r? ?DV+ V+rm@ m@`G*\ G*TA AFH' H.Q. Q(`:< `:r   