+
    Bic9                        ^ RI t ^ RIt^ RIt^ RIHt ^ RIHt ^ RIt^ RI	t	^ RI
t
^ RIt^ RIHt ]P                  ! RR7       ^
t^t]P                   ! 4       tR t ! R R	]P&                  4      t ! R
 R]4      t ! R R4      t ! R R]4      t ! R R]P0                  4      t ! R R]P&                  4      t]R8X  d   ]P6                  ! 4        R# R# )    N)support)threading_helper)
lock_testsT)modulec                     \         P                  '       d%   \        ;_uu_ 4        \        V 4       R R R 4       R # R #   + '       g   i     R # ; iN)r   verbose_print_mutexprint)args   &'/usr/lib/python3.14/test/test_thread.pyverbose_printr      s+    \#J \ \\s	   =A	c                   &   a  ] tR t^t o R tRtV tR# )BasicThreadTestc                n   \         P                  ! 4       V n        V P                  P                  4        \         P                  ! 4       V n        \         P                  ! 4       V n        ^ V n        ^ V n        ^ V n        \        P                  ! 4       pV P                  ! \        P                  .VO5!   R# r   N)threadallocate_lock
done_mutexacquirerunning_mutexrandom_mutexcreatedrunning
next_identr   threading_setup
addCleanupthreading_cleanup)selfkeys   & r   setUpBasicThreadTest.setUp   s     ..0!#113"002..0(::ASA    )r   r   r   r   r   r   N)__name__
__module____qualname____firstlineno__r!   __static_attributes____classdictcell____classdict__s   @r   r   r      s     
B 
Br#   r   c                      a  ] tR t^*t o R tR tR tR t]P                  ! ]
P                  R9  R4      R 4       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# )ThreadRunningTestsc                   V P                   ;_uu_ 4        V ;P                  ^,          un        \        RV P                  ,          4       \        P                  ! V P
                  V P                  34       V ;P                  ^,          un        V ;P                  ^,          un        RRR4       R#   + '       g   i     R# ; i)   zcreating task %sN)r   r   r   r   start_new_threadtaskr   r   r   s   &r   newtaskThreadRunningTests.newtask,   st    OOq O,t>?##DII/ABLLALLLAL  s   BB33C	c           	     J   V P                   ;_uu_ 4        \        P                  ! 4       R ,          pRRR4       \        RV: R\        XR,          4      : R24       \        P
                  ! V4       \        RV,          4       V P                  ;_uu_ 4        V ;P                  ^,          un        V P                  \        8X  d,   V P                  ^ 8X  d   V P                  P                  4        RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)     @Ntask  will run for     .Ausztask %s done)r   randomr   roundtimesleepr   r   r   NUMTASKSr   release)r   identdelays   && r   r1   ThreadRunningTests.task4   s    MMOg-E UE%)<LMN

5nu,-LLAL||x'DLLA,='')   
  s   C>AD>D	D"	c                &   \         P                  ! 4       ;_uu_ 4        \        \        4       F  pV P	                  4        K  	  \        R 4       V P                  P                  4        \        R4       RRR4       R#   + '       g   i     R# ; i)z waiting for tasks to complete...all tasks doneN)r   wait_threads_exitranger?   r3   r   r   r   r   is   & r   test_starting_threads(ThreadRunningTests.test_starting_threads?   sY    //118_ %<=OO##%*+ 2111s   AA??B	c                    V P                  \        P                  ! 4       ^ R4       \        P                  ! ^ 4       V P                  \        P                  ! 4       ^ R4       R# )r   zinitial stack size is not 0zstack_size not reset to defaultN)assertEqualr   
stack_sizer2   s   &r   test_stack_size"ThreadRunningTests.test_stack_sizeH   sH    **,a1NO!**,a1RSr#   ztest meant for nt and posixc                    \         P                  ! R 4       RpR	 FW  p\         P                  ! V4       V P                  \         P                  ! 4       W!V,          4       \        RV,          4       KY  	  R
 F  p\        RV,          4       ^ V n        ^ V n        \        P                  ! 4       ;_uu_ 4        \        \        4       F  pV P                  4        K  	  \        R4       V P                  P                  4        \        R4       RRR4       K  	  \         P                  ! ^ 4       R#   \         d    \        R4        EL5\         P                   d    T P                  R4        EL]i ; i  + '       g   i     EK  ; i)i   z3caught expected ValueError setting stack_size(4096)z4platform does not support changing thread stack sizez&stack_size(%d) failed - should succeedzsuccessfully set stack_size(%d)ztrying stack_size = (%d)z!waiting for all tasks to completerE   N)      r   )rR   rS   )r   rN   
ValueErrorr   errorskipTestrM   r   r   r   rF   rG   r?   r3   r   r   )r   fail_msgtssrI   s   &   r   test_nt_and_posix_stack_size/ThreadRunningTests.test_nt_and_posix_stack_sizeO   s0   	"d# <(Cc"V..0##~F;cAB )
 &C4s:;DODL!3355xALLN ) AB'')./ 65	 & 	!3  	0 / 0|| 	"MM ! "	" 655s*   D4 9AE94E6E6 E65E69Fc                0  aaa \         P                  ! 4       p\         P                  ! 4       oSP                  4        . oVV3R  lp\        P
                  ! 4       ;_uu_ 4        \         P                  ! VR4       \        P                  ! \        P                  4       F  pS'       g   K   M	  V P                  \         P                  ! 4       V^,           4       SP                  4        . o\        P                  ! VV3R l4      p?\        P                  ! \        P                  4       F"  pS'       d    M\        P                  ! 4        K$  	  V P                  \         P                  ! 4       V4       RRR4       R#   + '       g   i     R# ; i)c                  j   < SP                  R 4       S P                  4        S P                  4        R # r   )appendr   r@   )mutstarteds   r   r1   ,ThreadRunningTests.test__count.<locals>.tasku   s!    NN4 KKMKKMr#   c                 &   < SP                  R 4      # r   )r]   )_dones   &r   <lambda>0ThreadRunningTests.test__count.<locals>.<lambda>   s    T[[->r#   N )r   _countr   r   r   rF   r0   r   sleeping_retryLONG_TIMEOUTrM   r@   weakrefref
gc_collect)r   origr1   rb   wrrc   r^   r_   s   &    @@@r   test__countThreadRunningTests.test__countn   s   }}""$	
 //11##D"-++G,@,@A7 B V]]_dQh7 KKM
 DT#>?B++G,@,@A""$ B V]]_d3+ 2111s   $AF-CFF	c           	       a V3R  lp\         P                  ! 4       o\        P                  ! 4       ;_uu_ 4       p\        P
                  ! 4       ;_uu_ 4        SP                  4        \         P                  ! VR4       SP                  4        RRR4       V P                  \        VP                  P                  4      R4       V P                  VP                  P                  4       V P                  VP                  P                  RV: 24       V P                  VP                  P                   4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)c                  :   < S P                  4        \        R 4      h)task failed)r@   rT   )r_   s   r   r1   :ThreadRunningTests.test_unraisable_exception.<locals>.task   s    OO]++r#   Nrs   z'Exception ignored in thread started by rf   )r   r   r   catch_unraisable_exceptionr   rF   r   r0   rM   str
unraisable	exc_valueassertIsNoneobjecterr_msgassertIsNotNoneexc_traceback)r   r1   cmr_   s   &  @r   test_unraisable_exception,ThreadRunningTests.test_unraisable_exception   s    	, &&(//11R!3355!''b1! 6
 S!8!89=Ibmm223R]]22FthOQ  !<!<= 2155 211s$   E8E	B+EEEE)	c                T  a . oV3R  lp\         P                  ! 4       ;_uu_ 4        \        P                  ! V4      pVP	                  4        V P                  \        S4      ^4       V P                  VP                  S^ ,          4       RRR4       R#   + '       g   i     R# ; i)c                  |   < \         P                  ! R 4       S P                  \        P                  ! 4       4       R# )皙?N)r=   r>   r]   r   	get_ident)finisheds   r   r1   1ThreadRunningTests.test_join_thread.<locals>.task   s$    JJtOOF,,./r#   N)r   rF   r   start_joinable_threadjoinrM   lenrA   )r   r1   handler   s   &  @r   test_join_thread#ThreadRunningTests.test_join_thread   sr    	0 //1111$7FKKMS]A.V\\8A;7	 2111s   A%BB'	c                    R  p\         P                  ! 4       ;_uu_ 4        \        P                  ! V4      p\        P
                  ! R4       VP                  4        RRR4       R#   + '       g   i     R# ; i)c                      R # r   rf   rf   r#   r   r1   @ThreadRunningTests.test_join_thread_already_exited.<locals>.task       r#   r   N)r   rF   r   r   r=   r>   r   r   r1   r   s   &  r   test_join_thread_already_exited2ThreadRunningTests.test_join_thread_already_exited   sL    	 //1111$7FJJtKKM 2111s   =A((A9	c                    R  p\         P                  ! 4       ;_uu_ 4        \        P                  ! V4      pVP	                  4        VP	                  4        RRR4       R#   + '       g   i     R# ; i)c                      R # r   rf   rf   r#   r   r1   8ThreadRunningTests.test_join_several_times.<locals>.task   r   r#   Nr   rF   r   r   r   r   s   &  r   test_join_several_times*ThreadRunningTests.test_join_several_times   sI    	 //1111$7FKKMKKM	 2111s   7A""A3	c                   a \         P                  ! 4       oSP                  4        V3R  lp\        P                  ! 4       ;_uu_ 4        \         P
                  ! V4      p?SP                  4        RRR4       R#   + '       g   i     R# ; i)c                  (   < S P                  4        R # r   r   )handle_destroyeds   r   r1   9ThreadRunningTests.test_joinable_not_joined.<locals>.task   s    $$&r#   N)r   r   r   r   rF   r   r@   )r   r1   r   r   s   &  @r   test_joinable_not_joined+ThreadRunningTests.test_joinable_not_joined   sb    !//1  "	' //1111$7F$$& 2111s   
(A<<B	c                P  aaaa . o. o\         P                  ! 4       oSP                  4        \         P                  ! 4       oSP                  4        VVVV3R  lp\        P                  ! 4       ;_uu_ 4        \         P
                  ! V4      pSP                  V4       SP                  4        SP                  4        VP                  4        RRR4       V P                  \        R4      ;_uu_ 4        S^ ,          h  + '       g   i     L8; i  + '       g   i     R# ; i)c                     < SP                  4         S^ ,          P                  4        SP	                  4        R#   \         d   p SP                  T 4        Rp ? L3Rp ? ii ; i  SP	                  4        i ; ir   )r   r   	Exceptionr]   r@   )eerrorshandlesstart_joinable_thread_returnedtask_tried_to_joins    r   r1   4ThreadRunningTests.test_join_from_self.<locals>.task   s`    *224-
! #**,  !a  ! #**,s'   < A"AA% A""A% %A7NCannot join current thread)r   r   r   r   rF   r   r]   r@   r   assertRaisesRegexRuntimeError)r   r1   r   r   r   r   r   s   &  @@@@r   test_join_from_self&ThreadRunningTests.test_join_from_self   s    )/)=)=)?&&..0#113""$	- 	- //1111$7FNN6"*224&&(KKM 2 ##L2NOO)O 21 POOs   9AD7
DD	D%	c           	     j  aaaaa	 R  pRoRoV! 4       o	V! 4       oVVVV	3R lpV! 4       oVV3R lp\         P                  ! 4       ;_uu_ 4        \        P                  ! V4      oS	P	                  4        \        P                  ! V4      pSP	                  4        \
        P                  ! R4       SP                  4        SP                  4        VP                  4        V P                  \        R4      ;_uu_ 4        Sh  + '       g   i     M; i RRR4       R#   + '       g   i     R# ; i)c                  P    \         P                  ! 4       p V P                  4        V # r   )r   r   r   locks    r   	make_lock>ThreadRunningTests.test_join_then_self_join.<locals>.make_lock   s    '')DLLNKr#   Nc                     < SP                  4        SP                  4         SP                  4        R #   \         d   p T o R p ? R # R p ? ii ; ir   )r@   r   r   r   )r   rU   self_joiner_barrierself_joiner_handleself_joiner_starteds    r   self_joiner@ThreadRunningTests.test_join_then_self_join.<locals>.self_joiner   sC      '')'')"'') s   5 A AAc                  H   < S P                  4        SP                  4        R # r   )r@   r   )joiner_startedr   s   r   joiner;ThreadRunningTests.test_join_then_self_join.<locals>.joiner  s    ""$##%r#   皙?r   )r   rF   r   r   r   r=   r>   r@   r   r   r   )
r   r   r   r   joiner_handlerU   r   r   r   r   s
   &    @@@@@r   test_join_then_self_join+ThreadRunningTests.test_join_then_self_join   s    	
 !'k'k		 		 #	& //11!'!=!=k!J'') #88@M ""$ JJsO  '')##% ''6RSS TSS+ 2111s   B1D! D	DD!!D2	c                  a \         P                  ! 4       oSP                  4        V3R  lp\        P                  ! 4       ;_uu_ 4        \         P
                  ! V4      pVP                  R4       V P                  VP                  4       4       SP                  4        VP                  4        V P                  VP                  4       4       RRR4       R#   + '       g   i     R# ; i)c                  (   < S P                  4        R # r   r   r   s   r   thr6ThreadRunningTests.test_join_with_timeout.<locals>.thr(      LLNr#   r   N)r   r   r   r   rF   r   r   assertFalseis_doner@   
assertTrue)r   r   r   r   s   &  @r   test_join_with_timeout)ThreadRunningTests.test_join_with_timeout$  s    ##%	 //1111#6FKKV^^-.LLNKKMOOFNN,- 2111s   
BCC+	c                    \         P                  ! 4       pV P                  \        R 4      ;_uu_ 4        VP	                  4        RRR4       R#   + '       g   i     R# ; izthread not startedN)r   _ThreadHandler   r   r   r   r   s   & r   test_join_unstarted&ThreadRunningTests.test_join_unstarted3  s=    %%'##L2FGGKKM HGGG   AA 	c                    \         P                  ! 4       pV P                  \        R 4      ;_uu_ 4        VP	                  4        RRR4       R#   + '       g   i     R# ; ir   )r   r   r   r   	_set_doner   s   & r   test_set_done_unstarted*ThreadRunningTests.test_set_done_unstarted8  s@    %%'##L2FGG HGGGr   c           	       a \         P                  ! 4       oSP                  4        V3R  lp\         P                  ! 4       p\        P
                  ! 4       ;_uu_ 4        \         P                  ! WR7       V P                  \        R4      ;_uu_ 4        \         P                  ! WR7       RRR4       SP                  4        VP                  4        RRR4       R#   + '       g   i     L:; i  + '       g   i     R# ; i)c                  (   < S P                  4        R # r   r   r   s   r   func<ThreadRunningTests.test_start_duplicate_handle.<locals>.funcA  r   r#   r   zthread already startedN)r   r   r   r   r   rF   r   r   r   r@   r   )r   r   r   r   s   &  @r   test_start_duplicate_handle.ThreadRunningTests.test_start_duplicate_handle=  s    ##%	 %%'//11((=''6NOO,,TA PLLNKKM 21OO 211s$   6C2C	-(C2C/*C22D	c                    R  p\         P                  ! 4       ;_uu_ 4        \        P                  ! VRR7      pVP	                  4        RRR4       R#   + '       g   i     R# ; i)c                      R # r   rf   rf   r#   r   r   <ThreadRunningTests.test_start_with_none_handle.<locals>.funcM  r   r#   Nr   r   )r   r   r   s   &  r   test_start_with_none_handle.ThreadRunningTests.test_start_with_none_handleL  sB    	 //1111$tDFKKM 2111s   )AA%	)r   r   N)ntposix)r$   r%   r&   r'   r3   r1   rJ   rO   unittestskipIfosnamerY   ro   r   r   r   r   r   r   r   r   r   r   r   r   r(   r)   r*   s   @r   r-   r-   *   s     	*,T __RWWO35RS T<!4F>$8
':6p.

 r#   r-   c                   ,   a  ] tR tRt o R tR tRtV tR# )BarrieriU  c                    Wn         ^ V n        \        P                  ! 4       V n        \        P                  ! 4       V n        V P
                  P                  4        R# r   )num_threadswaitingr   r   checkin_mutexcheckout_mutexr   )r   r   s   &&r   __init__Barrier.__init__V  sC    &$224$224##%r#   c                .   V P                   P                  4        V P                  ^,           V n        V P                  V P                  8X  d5   V P                  ^,
          V n        V P                  P                  4        R# V P                   P                  4        V P                  P                  4        V P                  ^,
          V n        V P                  ^ 8X  d   V P                   P                  4        R# V P                  P                  4        R# )r/   N)r   r   r   r   r   r@   r2   s   &r   enterBarrier.enter]  s    ""$||a'<<4+++++a/DL'')""$##%||a'<<1&&(##%r#   )r   r   r   r   N)r$   r%   r&   r'   r   r   r(   r)   r*   s   @r   r   r   U  s     && &r#   r   c                   ,   a  ] tR tRt o R tR tRtV tR# )BarrierTestin  c                   \         P                  ! 4       ;_uu_ 4        \        \        4      V n        \        V n        \        \        4       F%  p\        P                  ! V P                  V34       K'  	  \        R 4       V P                  P                  4        \        R4       RRR4       R#   + '       g   i     R# ; i)zwaiting for tasks to endz
tasks doneN)r   rF   r   r?   barr   rG   r   r0   task2r   r   r   rH   s   & r   test_barrierBarrierTest.test_barrierp  sx    //11x(DH#DL8_''

QD9 %45OO##%,' 2111s   BB00C	c           
        \        \        4       F  pV^ 8X  d   ^ pM9V P                  ;_uu_ 4        \        P                  ! 4       R,          pRRR4       \	        RV: R\        XR,          4      : R24       \        P                  ! V4       \	        RV: RV: 24       V P                  P                  4        \	        RV,          4       K  	  V P                  ;_uu_ 4        V ;P                  ^,          un        V P                  ^ 8H  pRRR4       X'       d   V P                  P                  4        R# R#   + '       g   i     L; i  + '       g   i     LI; i)	r   r6   Nr7   r8   r9   r:   z
 entering ztask %s leaving barrier)rG   NUMTRIPSr   r;   r   r<   r=   r>   r   r   r   r   r   r@   )r   rA   rI   rB   r   s   &&   r   r   BarrierTest.task2z  s    xAz &&&"MMOg5E ' %"46 7JJu5!<=HHNN3e;< ! LLAL ||q(H   OO##%  '&  s   D>')E>EE!	)r   r   N)r$   r%   r&   r'   r   r   r(   r)   r*   s   @r   r   r   n  s     (& &r#   r   c                   .    ] tR tRt]P
                  tRtR# )	LockTestsi  rf   N)r$   r%   r&   r'   r   r   locktyper(   rf   r#   r   r  r    s    ##Hr#   r  c                   x   a  ] tR tRt o R t]P                  ! 4       ]P                  R 4       4       t	R t
RtV tR# )TestForkInThreadi  c                J    \         P                  ! 4       w  V n        V n        R # r   )r   piperead_fdwrite_fdr2   s   &r   r!   TestForkInThread.setUp  s    &(ggi#dmr#   c                  a R oV3R lp\         P                  ! 4       ;_uu_ 4        \        P                  ! WP                  V P
                  34       V P                  \        P                  ! V P                  ^4      R4       \        P                  ! V P
                  4       R R R 4       V P                  S4       \        P                  ! S^ R7       R #   + '       g   i     L;; i)Nc                   < \         P                  ! \        R R7      ;_uu_ 4        \        P                  ! 4       ;o'       d    RRR4       R#  RRR4        \        P
                  ! V 4       \        P                  ! VR4       \        P                  ! ^ 4       R#   + '       g   i     LV; i  \        P                  ! ^ 4       i ; i)ignore)categoryactionN   OK)warningscatch_warningsDeprecationWarningr   forkclosewrite_exit)r  r  pids   &&r   fork_thread7TestForkInThread.test_forkinthread.<locals>.fork_thread  s     ((2D08: : 779$C$: : %:!5): : s   B-B1 B.	1C	r  )exitcode)r   rF   r   r0   r  r  rM   r   readr  r|   r   wait_process)r   r  r  s   & @r   test_forkinthread"TestForkInThread.test_forkinthread  s     	$ //11##K,,1NORWWT\\15u=HHT]]# 2
 	S!S1- 21s   A>CC(	c                     \         P                  ! V P                  4        \         P                  ! V P                  4       R #   \         d     L0i ; i  \         d     R # i ; ir   )r   r  r  OSErrorr  r2   s   &r   tearDownTestForkInThread.tearDown  sS    	HHT\\"	HHT]]#	  		
  		s"    A  A AAA%$A%)r  r  N)r$   r%   r&   r'   r!   r   requires_forkr   reap_threadsr  r!  r(   r)   r*   s   @r   r  r    s?     0 "". # .:	 	r#   r  __main__)r   r   r;   testr   test.supportr   _threadr   r=   r  rj   r   requires_working_threadingr?   r   r   r
   r   TestCaser   r-   r   r   r  r  r$   mainrf   r#   r   <module>r,     s    	    )       + +4 8##%Bh'' Bh hV	& &2#&/ #&J$
$$ $,x(( ,^ zMMO r#   