
    vKg                       % S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
Jr  S SKJrJrJrJrJrJrJrJrJrJr  S SKrS SKrSSKJrJrJrJrJrJrJ r J!r!  SSK"J#r#  SSK$J%r%  SS	K&J'r'J(r(J)r)J*r*J+r+J,r,J-r-  SS
K.J/r/  \(       a  S SK0J1r1  SSK2J3r3  \\\4\\Rj                  \\6   4   4      r7\" S5      r8S<S jr9S<S jr:S<S jr;S<S jr<S<S jr=S=S>S jjr>S<S jr?S<S jr@S<S jrAS<S jrB      S?S jrC\R                  R                  S/ SQ5      \R                  R                  SSS/5      \R                  R                  SSS/5              S@S j5       5       5       rFS<S  jrGS<S! jrH    SAS" jrIS<S# jrJS<S$ jrK\R                  " S%5      rMS&\NS%'   S<S' jrOS<S( jrPS<S) jrQS<S* jrRS<S+ jrSS<S, jrTS<S- jrUS<S. jrVS<S/ jrWS<S0 jrXS<S1 jrYS<S2 jrZS<S3 jr[S<S4 jr\S<S5 jr]S<S6 jr^S<S7 jr_S<S8 jr`\%S<S9 j5       raS<S: jrbS<S; jrcg)B    )annotationsNpartial)
TYPE_CHECKINGAsyncGenerator	AwaitableCallableListNoReturnTupleTypeTypeVarUnion   )CancelScopeCapacityLimiterEvent_core
fail_aftermove_on_aftersleepsleep_forever)ki_self)slow)active_thread_countcurrent_default_thread_limiterfrom_thread_check_cancelledfrom_thread_runfrom_thread_run_syncto_thread_run_syncwait_all_threads_completed)wait_all_tasks_blocked)Outcome)TaskTc                   ^#    [         R                  " 5       m S
         SU4S jjjn [        R                  " 5       nSS jnU " [        USUS9I S h  vN   SS jnU " [        US[
        4US9I S h  vN   SS jnU " [        USUS9I S h  vN   SS	 jnU " [        US[        4US9I S h  vN   g  N_ NA N) N7f)Nc                0  >^ ^^^#    / mSU UUU4S jjn[         R                  " USS9nUR                  5         UR                  5       (       a5  [	        S5        [        S5      I S h  vN   UR                  5       (       a  M5  TSU4ST4U/:X  d   eg  N+7f)	Nc                   >  TR                  S[        R                  " 5       45        T" TTTS9n TR                  SU 45        g ! [         a1  n[	        U5        TR                  S[        U5      45         S nAg S nAff = f)Nstart
trio_tokengoterror)append	threadingcurrent_threadBaseExceptionprinttype)xexcdo_in_trio_threadfnrecordr+   s     X/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/trio/_tests/test_threads.pythreadfn<test_do_in_trio_thread.<locals>.check_case.<locals>.threadfnF   so    4w	(@(@(BCD%b&ZHuaj)  4c
wS	2334s   AA 
B 'A;;B T)targetdaemonyawn{Gz?r)   freturnNone)r/   Threadr)   is_aliver2   r   )r6   r7   expectedr+   r:   child_threadr8   trio_threads   `` `  @r9   
check_case*test_do_in_trio_thread.<locals>.check_case>   s       	4 	4 !''xE##%%&M+ ##%% 7L1C3ExPPPP s   A!B(B)BBc                    [         R                  " 5       (       a   eU R                  S[        R                  " 5       45        g)Nr@   r   )r   currently_ki_protectedr.   r/   r0   r8   s    r9   f1"test_do_in_trio_thread.<locals>.f1X   s4    //1111sI44678    )r,   r   r*   c                    [         R                  " 5       (       a   eU R                  S[        R                  " 5       45        [
        eNr@   )r   rL   r.   r/   r0   
ValueErrorrM   s    r9   f2"test_do_in_trio_thread.<locals>.f2_   s7    //1111sI44678rP   r-   c                   #    [         R                  " 5       (       a   e[         R                  " 5       I S h  vN   U R                  S[        R
                  " 5       45        g N+7f)Nr@      )r   rL   
checkpointr.   r/   r0   rM   s    r9   f3"test_do_in_trio_thread.<locals>.f3f   sN     //1111   sI44678 	!s   5A%A#,A%)r,   rW   c                   #    [         R                  " 5       (       a   e[         R                  " 5       I S h  vN   U R                  S[        R
                  " 5       45        [        e N07frR   )r   rL   rX   r.   r/   r0   KeyErrorrM   s    r9   f4"test_do_in_trio_thread.<locals>.f4n   sP     //1111   sI44678 	!s   5A*A(1A*N)
r6   zCallable[..., threading.Thread]r7   zCallable[..., T | Awaitable[T]]rF   ztuple[str, T]r+   _core.TrioToken | NonerB   rC   )r8   
RecordTyperB   int)r8   ra   rB   r   )r/   r0   r   current_trio_tokenr   rS   r   r\   )rI   tokenrN   rT   rY   r]   rH   s         @r9   test_do_in_trio_threadre   ;   s     **,K .2	Q:Q+Q  Q +	Q
 
Q Q0 $$&E
 )2ze
LLL
 )2/DQV
WWW _b*
GGG _b7H*=%
PPP/ M X H QsH   AB?B7B?7B98B?B;B?1B=2B?9B?;B?=B?c                   #    [         R                  " [        5         [        S 5        S S S 5        SS jn [         R                  " [        5         [	        U 5        S S S 5        g ! , (       d  f       NB= f! , (       d  f       g = f7f)Nc                     g r_    rh   rP   r9   <lambda>9test_do_in_trio_thread_from_trio_thread.<locals>.<lambda>y       TrP   c                    #    g 7fr_   rh   rh   rP   r9   foo4test_do_in_trio_thread_from_trio_thread.<locals>.foo{           rA   )pytestraisesRuntimeErrorr   r   )rm   s    r9   'test_do_in_trio_thread_from_trio_threadrt   w   sR     	|	$\* 
% 
|	$ 
%	$ 
%	$ 
%	$s3   BA&'BA7	B&
A40B7
BBc                 j   ^ [        5       mSU4S jjn [        R                  " U 5        TSS1:X  d   eg )Nc                   >^^^#    [         R                  " 5       mS	S jmS	U4S jjmS	UUUU4S jjn [        R                  " U S9nUR	                  5         [        S5        UR                  5       (       a*  [        S5      I S h  vN   UR                  5       (       a  M*  [        S5        UR                  5         [        S5        g  NB7f)
Nc                    [        S5        [        R                  " 5       (       a   e[        S5         [        5         SS Kn [        SU R
                  " 5       5        g ! SS Kn [        SU R
                  " 5       5        f = f)Nzin Trio threadr   r   finally)r2   r   rL   r   sysexc_info)ry   s    r9   trio_thread_fnTtest_run_in_trio_thread_ki.<locals>.check_run_in_trio_thread.<locals>.trio_thread_fn   s\    "#335555)1	i0 i0s   
A !A?c                    >#    T " 5         g 7fr_   rh   )r{   s   r9   trio_thread_afnUtest_run_in_trio_thread_ki.<locals>.check_run_in_trio_thread.<locals>.trio_thread_afn   s     s   	c                    >  [        S5        [        TTS9   [	        TTS9  g ! [         a    [        S5        T R                  S5         N4f = f! [         a    [        S5        T R                  S5         g f = f)Nrunningr*   ok1ok2)r2   r   KeyboardInterruptaddr   )r8   rd   r~   r{   s   r9   external_thread_fnXtest_run_in_trio_thread_ki.<locals>.check_run_in_trio_thread.<locals>.external_thread_fn   sp    "i $^F"EB	 % "e

5!"
 % "e

5!"s    $ 
A &AA&A98A9)r<   waitingr?   zwaited, joiningdonerA   )	r   rc   r/   rD   r)   r2   rE   r   join)r   threadrd   r~   r{   r8   s     @@@r9   check_run_in_trio_thread<test_run_in_trio_thread_ki.<locals>.check_run_in_trio_thread   s     ((*		1		" 	" !!);<ioo+ oo f s   B CC	C"(Cr   r   rA   )setr   run)r   r8   s    @r9   test_run_in_trio_thread_kir      s3     UF%N 
II&'eU^###rP   c                    ^^^^ / m[        5       mSUU4S jjmSUU4S jjmSUUU4S jjn [        R                  " U 5      nUR                  5         TSS/:X  d   eg )	Nc                    >#    TR                  S5        T R                  5         [        R                  " S 5      I S h  vN   g  N7f)Nsleepingc                6    [         R                  R                  $ r_   )r   Abort	SUCCEEDED)_s    r9   ri   Mtest_await_in_trio_thread_while_main_exits.<locals>.trio_fn.<locals>.<lambda>   s    EKK4I4IrP   )r.   r   r   wait_task_rescheduled)evr8   s   r9   trio_fn;test_await_in_trio_thread_while_main_exits.<locals>.trio_fn   s0     j!
))*IJJJs   <AA Ac                r   >  [        TU S9  g ! [        R                   a    TR                  S5         g f = f)Nr*   	cancelled)r   r   	Cancelledr.   )rd   r8   r   s    r9   	thread_fn=test_await_in_trio_thread_while_main_exits.<locals>.thread_fn   s1    	'G6 	'MM+&	's   
 %66c                    >#    [         R                  " 5       n [        R                  " TU 4S9nUR	                  5         TR                  5       I S h  vN   TS/:X  d   eU$  N7f)N)r<   argsr   )r   rc   r/   rD   r)   wait)rd   r   r   r8   r   s     r9   main8test_await_in_trio_thread_while_main_exits.<locals>.main   sX     ((*!!%Bggi*%%% 	s   AA$A"A$r   r   rA   )rd   _core.TrioTokenrB   rC   )rB   threading.Thread)r   r   r   r   )r   r   r   r8   r   r   s     @@@@r9   *test_await_in_trio_thread_while_main_exitsr      sZ    F	BK K
' '  YYt_F
KKMj+....rP   c                 h  ^^#    Sn SU -   4SS jjmSU4S jjm[        T5      I S h  vN   [        TS S9I S h  vN   [        T" SU -   5      5      I S h  vN   SU4S jjnU" S5      I S h  vN   U" S	5      I S h  vN   U" S
5      I S h  vN   U" S5      I S h  vN   g  N{ Nk NQ N; N- N N7f)Nz0 from trio._tests.test_threads.test_named_threadinnerc                v    [         R                  " 5       R                  U :X  d   e[         R                  " 5       $ r_   )r/   r0   name)r   s    r9   r    test_named_thread.<locals>.inner   s.    '')..$666''))rP   c                   > [        TU 5      $ r_   r   r   r   s    r9   r@   test_named_thread.<locals>.f       ud##rP   thread_namerC   c                   >#    [        T" U 5      U S9I S h  vN n[        R                  " SUR                  5      (       d   eg  N-7f)Nr   Trio thread [0-9]*)r    rematchr   )r   r   r@   s     r9   test_thread_name+test_named_thread.<locals>.test_thread_name   s;     )!D'tDDxx,fkk:::: Es   AA.A fobiedooname_longer_than_15_characters   💙r   strrB   r   r   r   rB   z"Callable[[None], threading.Thread])r   r   rB   rC   r    )endingr   r@   r   s     @@r9   test_named_threadr      s     ?F!F* *$ U
###
U
555 Qv/
000; 2

:
&&&
;
<<<
6
""" $5 1 &<"sy   $B2B$B2B&B2B(B2.B*/B2>B,?B2B.B2B0B2&B2(B2*B2,B2.B20B2c                   SS K nSS KnUR                  R                  S5      nU(       d  Sn UR	                  U5      n[        USS 5      nU(       d   eUR                  UR                  UR                  /Ul        UR                  Ul        UR!                  SSS9nU c  ["        R$                  " 5       n U" XS5      S:X  d   e UR&                  R)                  5       $ ! [
         a    [        S[        R                   35         g f = f! [*         a1  n[,        R.                  " S	UR&                  < S
U 35         S nAg S nAff = f)Nr   pthreadzlibc.sozno pthread on pthread_getname_nprP      )sizezvalue: z, exception: )ctypesctypes.utilutilfind_libraryCDLL	Exceptionr2   ry   platformgetattrc_void_pc_char_pc_size_targtypesc_intrestypecreate_string_bufferr/   	get_identvaluedecodeUnicodeDecodeErrorrq   fail)identr   libpthread_path
libpthreadr   name_bufferes          r9   _get_thread_namer      s<   kk..y9O $[[1

 !-A4H  	#
 "(--c-;K}##%e"5:::E  ''))-  s||n-..  Egk//2-sCDDEs)   C  D  &D	D	
E'EEc                 :  ^^#    SS jmSU4S jjmSn [        T" U 5      5      I S h  vN   [        T" U 5      S S9I S h  vN   SSU4S jjjnU" S5      I S h  vN   U" S5      I S h  vN   U" S5      I S h  vN   U" S	S
S9I S h  vN   g  Nf NP N8 N* N N7f)Nc                    [        5       nUc<  [        R                  S:w  a(  [        R                  " S[        R                   35        O
XS S :X  d   e[
        R                  " 5       $ )Nlinuxzno pthread OS support on    )r   ry   r   rq   skipr/   r0   )r   os_thread_names     r9   r   #test_named_thread_os.<locals>.inner  sT    )+!cllg&=KK3CLL>BC!#2Y...''))rP   c                   > [        TU 5      $ r_   r   r   s    r9   r@   test_named_thread_os.<locals>.f#  r   rP   z4None from trio._tests.test_threads.test_named_threadr   c                   >#    Uc  U n[        T" U5      U S9I S h  vN n[        UR                  5      nUc   S5       e[        R                  " SU5      (       d   eg  NB7f)Nr   z'should skip earlier if this is the caser   )r    r   r   r   r   )r   rF   r   r   r@   s       r9   r   .test_named_thread_os.<locals>.test_thread_name,  sb     H)!H+4HH)&,,7)T+TT)xx,n====	 Is   A!AAA!r   r   r   r   ?)rF   r   r   r_   )r   r   rF   
str | NonerB   rC   r   )defaultr   r@   r   s     @@r9   test_named_thread_osr     s     *$ EG
QwZ
(((
QwZT
:::> > 2

:
&&&
;
<<<
6C
000# ): &<0si   $BBB BBBB*B+B:B;B	B
BBBBBBc                    #    SSK Jn   U " 5       nUc>  [        R                  S:w  d   e[        R
                  " S[        R                   35        g g 7f)Nr   )get_os_thread_name_funcr   zno pthread_setname_np on )trio._core._thread_cacher   ry   r   rq   r   )r   ks     r9   test_has_pthread_setname_npr   <  sD     @!Ay||w&&&/~>? s   AAc                   #    [         R                  " 5       n SS jn[        US5      I S h  vN u  p#US:X  d   eX0:w  d   eSS jn[        R                  " [
        SS9 n[        U5      I S h  vN   S S S 5        [        WR                  R                  5        UR                  R                  S   U :w  d   eg  N NM! , (       d  f       NQ= f7f)	Nc                0    U [         R                  " 5       4$ r_   )r/   r0   )r4   s    r9   r@   $test_run_in_worker_thread.<locals>.fH  s    9++-..rP      c                 >    [        [        R                  " 5       5      er_   )rS   r/   r0   rh   rP   r9   g$test_run_in_worker_thread.<locals>.gO  s    11344rP   z1^<Thread\(Trio thread \d+, started daemon \d+\)>$r   r   )r4   r%   rB   ztuple[T, threading.Thread])rB   r   )	r/   r0   r    rq   rr   rS   r2   r   r   )rH   r@   r4   rG   r   excinfos         r9   test_run_in_worker_threadr  E  s     **,K/ /q!44OA6M6&&&5 
B
 
 ###	

 
'--

==a K/// 5 	$	
 
s:   *CB;3C B?/B=0B?4AC=B??
C	Cc                   ^^^#    S /mSU4S jjmSUU4S jjn / m[         R                  " 5       n[        R                  " 5        IS h  vN nUR	                  XS5        [        5       I S h  vN   TS/:X  d   eUR                  R                  5         S S S 5      IS h  vN   TS   S:w  d   eUR                  S 5        TS   S:w  a!  [        R                  " S5        TS   S:w  a  M!  / mS TS'   [        R                  " 5        IS h  vN nUR	                  XS5        [        5       I S h  vN   UR                  R                  5         [        R                  " SS	9   [        S
5       H   n[        R                  " 5       I S h  vN   M"     S S S 5        TS/:X  d   eUR                  S 5        S S S 5      IS h  vN   [        R                  " 5        nUR                  5         U " US5      I S h  vN   S S S 5        WR                  (       d   eg  GN GN GN}! , IS h  vN  (       d  f       GN= f GN0 GN N! , (       d  f       N= f N! , IS h  vN  (       d  f       N= f Ny! , (       d  f       N}= f7f)Nc                :   > STS'   U R                  5         STS'   g )Nblockingr   finished)get)qregisters    r9   r@   1test_run_in_worker_thread_cancellation.<locals>.f^  s     	 rP   c                   >#    TR                  S5         [        TXS9I S h  vN TR                  S5        $  N! TR                  S5        f = f7f)Nr)   abandon_on_cancelexit)r.   r    )r  r  r@   r8   s     r9   child5test_run_in_worker_thread_cancellation.<locals>.childd  sC     g	"+AqVVMM&! WMM&!s%   A; 9; A; AATr)   r   r  r?   Fshield
   )r  zstdlib_queue.Queue[str]rB   rC   )r  zstdlib_queue.Queue[None]r  boolrB   rC   )stdlib_queueQueuer   open_nursery
start_soonr"   cancel_scopecancelputtimer   r   rangerX   cancelled_caught)r  r  nurseryr   scoper@   r8   r  s        @@@r9   &test_run_in_worker_thread_cancellationr   [  s     "&H!" " F"."4"4"6A!!##w5T* %&&&'"""##% $# A;*$$$EE$K
1+
#

4 1+
# FHQK!!##w5U+$&&&##%d+2Y&&(((  , '"""	d $# 
			Auo 
 !!!!I $
 	' $###& $& ) ,+	 $###  	 
	s	  AJ
HJ H!.H/'H!J!H"AJ, JH<J I0H?12I#'I
I
I"I5J IJI37I18I3<JH!J!H9'H*(H94	J?II
I	IJI.I I.*J1I33
J=Jc                  ^^^ UR                  [        R                  SS5        [        R                  " 5       m[        R                  " 5       mSUU4S jjmSU4S jjn[        R
                  " U5        TR                  S 5        TR                  5       nUR                  5       (       a-  [        R                  " S5        UR                  5       (       a  M-  U R                  5       u  pESU;  d   eSU;  d   eg )NIDLE_TIMEOUTr?   c                 n   > T R                  5         TR                  [        R                  " 5       5        g r_   )r  r  r/   r0   )q1q2s   r9   r   6test_run_in_worker_thread_abandoned.<locals>.thread_fn  s!    

y'')*rP   c                 4  >#    SU4S jjn [         R                  " 5        IS h  vN nUR                  U 5        [        5       I S h  vN   UR                  R                  5         S S S 5      IS h  vN   g  NR N1 N	! , IS h  vN  (       d  f       g = f7f)Nc                 6   >#    [        T SS9I S h  vN   g  N7f)NTr  r   )r   s   r9   r  @test_run_in_worker_thread_abandoned.<locals>.main.<locals>.child  s     $Y$GGGs   rA   )r   r  r  r"   r  r  )r  r  r   s     r9   r   1test_run_in_worker_thread_abandoned.<locals>.main  sg     	H %%''7u%(***  '') (''* ('''sV   "BA8BA>A:	A>'B2A<3B:A><B>BBBBzException in threadrA   )setattrr   _thread_cacher  r  r   r  r  rE   r  r   
readouterr)	capfdmonkeypatchr   r   outerrr$  r%  r   s	         @@@r9   #test_run_in_worker_thread_abandonedr2    s     ++^TB#/#5#5#7B/;/A/A/CB+ +* 
IIdOFF4L VVXF
//



4 //

 !HC +++ +++rP   MAX)rW      r  r  FTuse_default_limiterc                  ^^
^^^^^#    SU -  n[         R                  " 5       m
[         R                  " 5       mU(       a  [        5       nUR                  nXl        S mO[        U 5      nU nUm  " S S5      mSTl        STl        STl        STl	        [        R                  " 5       mSU
UUU4S jjmSUUU4S jjn[        R                  " 5        IS h  vN n[        S5        / n[        U5       HB  n	UR                  [        5       5        UR!                  XhS   5        [#        5       I S h  vN   MD     T(       a8  [        S	5        US   R%                  5       I S h  vN   [#        5       I S h  vN   TR                  U :w  d  UR'                  5       R(                  U :w  aE  [+        S
5      I S h  vN   TR                  U :w  a  M%  UR'                  5       R(                  U :w  a  ME  T
R-                  5         S S S 5      IS h  vN   TR                  U :X  d   eT(       a5  UR.                  S:  a%  [+        S
5      I S h  vN   UR.                  S:  a  M%  TR                  U:X  d   eTR                  S:X  d   e XTl        g  GN GNX GN* GN N N! , IS h  vN  (       d  f       N= f Nl! XTl        f = f7f)Nr   c                  >    \ rS rSr% S\S'   S\S'   S\S'   S\S'   Srg)	0test_run_in_worker_thread_limiter.<locals>.statei  rb   ran
high_waterr   parkedrh   N)__name__
__module____qualname____firstlineno____annotations____static_attributes__rh   rP   r9   stater8    s    HOLKrP   rB  r   c                  > [        S5        [        U R                  TS9  T   T=R                  S-  sl        T=R                  S-  sl        [        TR                  TR                  5      Tl        T=R                  S-  sl        S S S 5        TR                  5         T   T=R                  S-  sl        T=R                  S-  sl        S S S 5        [        S5        g ! , (       d  f       N_= f! , (       d  f       N+= f)Nzthread_fn startr*   r   zthread_fn exiting)	r2   r   r  r9  r   maxr:  r;  r   )r  gatelockrB  rd   s    r9   r   4test_run_in_worker_thread_limiter.<locals>.thread_fn  s    #$ !4!4G		Q	"#&u'7'7#G  !  IIK!"  %&  s   A%C!"+C2!
C/2
D c                   >#    [         R                  " 5        n[        TUTTS9I S h  vN   S S S 5        [        SWR                  5        U R                  5         g  N3! , (       d  f       N7= f7f)N)r  limiterzrun_thread finished, cancelled:)r   r   r    r2   r  r   )eventr  r  limiter_argr   s     r9   
run_thread5test_run_in_worker_thread_limiter.<locals>.run_thread  s`     ""$( &,'	   % 3\5R5RSIIK %$s+   A0AAA/A0A
A-)A0spawningz'waiting for first cancellation to clearr?   )r  r   rB   rC   )rJ  r   rB   rC   )r/   r   Lockr   total_tokensr   r9  r:  r   r;  r   rc   r  r2   r  r.   r  r"   r   
statisticstasks_waitingr   r   borrowed_tokens)r3  r  r5  COUNTcorig_total_tokensrL  r  eventsr   rE  rK  rF  rB  r   rd   s    `        @@@@@@r9   !test_run_in_worker_thread_limiterrY    s>     GE??D>>D*,NNC [+	 	 	((*	' 	' 		 		 %%''7*F5\eg&"":bz:,... " ?@Qinn&&&,... #q||~'C'Cs'JDk!! #q||~'C'Cs'J HHJ5 ('8 3&&& ##a'Dk!! ##a' yyE!!!}}!!!*Q ( / '. "1 ('''F "
 +s   A%J>/A)J3 JJ3 AJ2J
30J#J$J5J6A J6J7JJ-J=J3 J	;J3 J1J3 $J3  J>J3 
JJJJJ3 J.J J.*J3 3J;;J>c                 t   ^#    / m " U4S jS5      n [        S U " 5       S9I S h  vN   TSS/:X  d   eg  N7f)Nc                  6   > \ rS rSrSU 4S jjrSU 4S jjrSrg)?test_run_in_worker_thread_custom_limiter.<locals>.CustomLimiteri9  c                <   >#    TR                  S5        Xl        g 7fNacquirer.   	_borrowerselfborrowerr8   s     r9   acquire_on_behalf_ofTtest_run_in_worker_thread_custom_limiter.<locals>.CustomLimiter.acquire_on_behalf_of:  s     MM)$%Ns   c                J   > TR                  S5        XR                  :X  d   eg )Nreleaser`  rb  s     r9   release_on_behalf_ofTtest_run_in_worker_thread_custom_limiter.<locals>.CustomLimiter.release_on_behalf_of>  s    MM)$~~---rP   )ra  Nrd  r$   rB   rC   r<  r=  r>  r?  re  ri  rA  rM   s   r9   CustomLimiterr\  9  s    	&	. 	.rP   rm  c                     g r_   rh   rh   rP   r9   ri   :test_run_in_worker_thread_custom_limiter.<locals>.<lambda>D  rk   rP   rI  r_  rh  r   )rm  r8   s    @r9   (test_run_in_worker_thread_custom_limiterrq  4  sD      F. . \=?
CCCi++++ Ds   #868c                   ^^#    / m " U4S jS5      n U " 5       n[         R                  " [        SS9 n[        S US9I S h  vN   S S S 5        WR                  R
                  b   eTSS/:X  d   e/ m0 m[         R                  " [        SS9 n[        U4S	 jUS9I S h  vN   S S S 5        [        UR                  R
                  [        5      (       d   eTSS/:X  d   eg  N! , (       d  f       N= f NU! , (       d  f       NY= f7f)
Nc                  6   > \ rS rSrSU 4S jjrSU 4S jjrSrg)Ctest_run_in_worker_thread_limiter_error.<locals>.BadCapacityLimiteriK  c                0   >#    TR                  S5        g 7fr^  )r.   rb  s     r9   re  Xtest_run_in_worker_thread_limiter_error.<locals>.BadCapacityLimiter.acquire_on_behalf_ofL  s     MM)$s   c                <   > TR                  S5        [        S5      e)Nrh  zrelease on behalf)r.   rS   rb  s     r9   ri  Xtest_run_in_worker_thread_limiter_error.<locals>.BadCapacityLimiter.release_on_behalf_ofO  s    MM)$011rP   rh   Nrk  )rd  r$   rB   r   rl  rM   s   r9   BadCapacityLimiterrt  K  s    	%	2 	2rP   ry  z^release on behalf$r   c                     g r_   rh   rh   rP   r9   ri   9test_run_in_worker_thread_limiter_error.<locals>.<lambda>V      rP   rp  r_  rh  c                    > T S   $ )Nr4   rh   )ds   r9   ri   r{  _  s	    3rP   )rq   rr   rS   r    r   __context__
isinstancer\   )ry  bsr   r~  r8   s      @@r9   'test_run_in_worker_thread_limiter_errorr  H  s     F2 2 
	B	z)>	?7 r::: 
@==$$,,,i++++F A	z)>	?7 <<< 
@gmm//::::i++++ 	; 
@	? 	= 
@	?sY   0DC'C%C'ADC:"C8#C:'>D%C''
C51D8C::
DDc                  #    SS jnU R                  [        R                  R                  SU5        [	        5       nUR
                  S:X  d   e[        R                  " [        5       n[        S 5      I S h  vN   S S S 5        S[        WR                  5      ;   d   eUR
                  S:X  d   eg  N:! , (       d  f       N>= f7f)Nc                    [        S5      e)Nz!the engines canna take it captain)rs   )rc  r   s     r9   	bad_start:test_run_in_worker_thread_fail_to_spawn.<locals>.bad_starth  s    >??rP   start_thread_soonr   c                     g r_   rh   rh   rP   r9   ri   9test_run_in_worker_thread_fail_to_spawn.<locals>.<lambda>r  r|  rP   engines)rc  objectr   r  rB   r   )r+  r   r,  ThreadCacher   rT  rq   rr   rs   r    r   r   )r/  r  rI  r   s       r9   'test_run_in_worker_thread_fail_to_spawnr  d  s     @ ++779LiX,.G""a''' 
|	$ ... 
%GMM****""a''' 	/ 
%	$s0   A'C)B69B4:B6>6C4B66
C Cc                 x   #    SS jn [         R                  " 5       n[        U 5      I S h  vN nX!:X  d   eg  N7f)Nc                 8    [        [        R                  5      n U $ r_   r   r   rc   callee_tokens    r9   r   5test_trio_to_thread_run_sync_token.<locals>.thread_fn{      +E,D,DErP   rB   r   r   rc   r    r   caller_tokenr  s      r9   "test_trio_to_thread_run_sync_tokenr  x  8      ++-L+I66L''' 7   ):8:c                    #    SS jn [         R                  " [        SS9   [        U 5      I S h  vN   S S S 5        g  N! , (       d  f       g = f7f)Nc                    #    g 7fr_   rh   rh   rP   r9   async_fn=test_trio_to_thread_run_sync_expected_error.<locals>.async_fn  ro   rp   zexpected a sync functionr   rA   )rq   rr   	TypeErrorr    r  s    r9   +test_trio_to_thread_run_sync_expected_errorr    s>      
y(B	C *** 
D	C* 
D	Cs)   AA >A 	AA  
A
Atrio_test_contextvarzcontextvars.ContextVar[str]c                   #    [         R                  " 5       n [        R                  S5        SS jn[	        U5      I S h  vN u  p#US:X  d   eX0:w  d   eSS jn[	        U5      I S h  vN u  pVn[        R                  5       nUS:X  d   eUS:X  d   eUS:X  d   S5       e[        R                  " 5       S:X  d   eg  N} NV7f)	Nr   c                     [         R                  5       n [        R                  " [        R
                  5         [        R                  " 5         S S S 5        U [        R                  " 5       4$ ! , (       d  f       N%= fr_   )	r  r  rq   rr   sniffioAsyncLibraryNotFoundErrorcurrent_async_libraryr/   r0   )r   s    r9   r@   3test_trio_to_thread_run_sync_contextvars.<locals>.f  sP    $((*]]7<<=))+ >y//122 >=s   A..
A<c                 R   [         R                  5       n [         R                  S5        [         R                  5       n[        R                  " [
        R                  5         [
        R                  " 5         S S S 5        U U[        R                  " 5       4$ ! , (       d  f       N&= f)Nworker)
r  r  r   rq   rr   r  r  r  r/   r0   )parent_valueinner_values     r9   r   3test_trio_to_thread_run_sync_contextvars.<locals>.g  sv    +//1  **..0]]7<<=))+ > $$&
 	
 >=s   "B
B&r  zRThe contextvar value set on the worker would not propagate back to the main threadtrio)rB   ztuple[str, threading.Thread])rB   z!tuple[str, str, threading.Thread])r/   r0   r  r   r    r  r  r  )rH   r@   r   rG   r   r  r  current_values           r9   (test_trio_to_thread_run_sync_contextvarsr    s     **,KV$3 !31 55EF??&&&

 5Gq4I.I+L|(,,.M6!!!("""F" 	" ((*f4441 6  /Js$   >C B>(C)C *AC Cc                   ^#    SS jn [        U 5      I S h  vN n[        U[        5      (       d   eSS jmSU4S jjn[        R                  " [
        SS9   [        U5      I S h  vN   S S S 5        g  N^ N! , (       d  f       g = f7f)Nc                 8    [        [        R                  5      n U $ r_   )r   r   current_time)	trio_times    r9   thread_fn_13test_trio_from_thread_run_sync.<locals>.thread_fn_1  s    (););<	rP   c                    #    g 7fr_   rh   rh   rP   r9   r  0test_trio_from_thread_run_sync.<locals>.async_fn  ro   rp   c                    > [        T 5        g r_   )r   r  s   r9   thread_fn_23test_trio_from_thread_run_sync.<locals>.thread_fn_2  s    X&rP   zexpected a synchronous functionr   )rB   floatrA   )r    r  r  rq   rr   r  )r  r  r  r  s      @r9   test_trio_from_thread_run_syncr    sr      )55Ii''''' 
y(I	J --- 
K	J 6 	. 
K	Js:   BA6ABA:(A8)A:-
B8A::
BBc                   ^^#    / mSU4S jjmSUU4S jjn [        U 5      I S h  vN   TSS/:X  d   eSS jn[        R                  " [        SS9   [        [        U5      I S h  vN   S S S 5        g  NN N! , (       d  f       g = f7f)	Nc                 Z   >#    [         R                  " 5         T R                  S5        g 7f)Nback in trio)r   r  r.   rM   s   r9   back_in_trio_fn2test_trio_from_thread_run.<locals>.back_in_trio_fn  s     n%s   (+c                 >   > TR                  S5        [        T 5        g )N	in thread)r.   r   )r  r8   s   r9   r   ,test_trio_from_thread_run.<locals>.thread_fn  s    k"(rP   r  r  c                     g r_   rh   rh   rP   r9   sync_fn*test_trio_from_thread_run.<locals>.sync_fn  s    rP   zappears to be synchronousr   rA   )r    rq   rr   r  r   )r   r  r  r8   s     @@r9   test_trio_from_thread_runr    s      F&) ) Y
'''k>2222 
y(C	D '::: 
E	D ( 	; 
E	Ds9   "B
A5,B
A9'A7(A9,
B
7A99
BB
c                 x   #    SS jn [         R                  " 5       n[        U 5      I S h  vN nX!:X  d   eg  N7f)Nc                 8    [        [        R                  5      n U $ r_   r  r  s    r9   r   .test_trio_from_thread_token.<locals>.thread_fn  r  rP   r  r  r  s      r9   test_trio_from_thread_tokenr    r  r  c                 x   #    SS jn [         R                  " 5       n[        X5      I S h  vN nX!:X  d   eg  N7f)Nc                6    [        [        R                  U S9nU$ )Nr*   r  )rd   r  s     r9   r   4test_trio_from_thread_token_kwarg.<locals>.thread_fn  s    +E,D,DQVWrP   )rd   r   rB   r   r  r  s      r9   !test_trio_from_thread_token_kwargr    s9      ++-L+IDDL''' Er  c                    #    [         R                  " [        5         [        [        R
                  5        S S S 5        g ! , (       d  f       g = f7fr_   rq   rr   rs   r   r   r  rh   rP   r9   test_from_thread_no_tokenr    s,      
|	$U//0 
%	$	$s   AA 	A 
A
Ac                 6  #    [         R                  S5        SS jn [        U 5      I S h  vN u  nnnnn[         R                  5       nXas=:X  a  S:X  d   e   eX$s=:X  a  Us=:X  a  S:X  d   e   e[        R
                  " 5       S:X  d   eUS:X  d   eg  Nk7f)Nr   c                 "   [         R                  5       n [         R                  S5        [         R                  5       n[        R                  " [
        R                  5         [
        R                  " 5         S S S 5        SS jn[        U5      u  p4[         R                  5       n[        R                  " [
        R                  5         [
        R                  " 5         S S S 5        U UUUU4$ ! , (       d  f       N}= f! , (       d  f       N&= f)Nr  c                     [         R                  5       n [         R                  S5        [         R                  5       n[        R                  " 5       S:X  d   eX4$ Nback_in_mainr  r  r  r   r  r  back_parent_valueback_current_values     r9   r  Stest_trio_from_thread_run_sync_contextvars.<locals>.thread_fn.<locals>.back_in_main  sN     4 8 8 : $$^4!5!9!9!;002f<<<$88rP   rB   ztuple[str, str])	r  r  r   rq   rr   r  r  r  r   )thread_parent_valuethread_current_valuer  r  r  thread_after_values         r9   r   =test_trio_from_thread_run_sync_contextvars.<locals>.thread_fn  s    2668  *3779]]7<<=))+ >	9 1E\0R-1557]]7<<=))+ >   
 	
 >= >=   "C/
D /
C= 
Dr  r  r  rB   ztuple[str, str, str, str, str]r  r   r    r  r  r  r   r  r  r  r  r  r  s          r9   *test_trio_from_thread_run_sync_contextvarsr    s     V$
@ !++(,,.M9699999V8JVhVVVVV((*f444/// 	,   )BBA,Bc                 6  #    [         R                  S5        SS jn [        U 5      I S h  vN u  nnnnn[         R                  5       nXas=:X  a  S:X  d   e   eX$s=:X  a  Us=:X  a  S:X  d   e   eUS:X  d   e[        R
                  " 5       S:X  d   eg  Nk7f)Nr   c                 "   [         R                  5       n [         R                  S5        [         R                  5       n[        R                  " [
        R                  5         [
        R                  " 5         S S S 5        SS jn[        U5      u  p4[         R                  5       n[        R                  " [
        R                  5         [
        R                  " 5         S S S 5        U UUUU4$ ! , (       d  f       N}= f! , (       d  f       N&= f)Nr  c                    #    [         R                  5       n [         R                  S5        [         R                  5       n[        R                  " 5       S:X  d   eX4$ 7fr  r  r  s     r9   async_back_in_mainTtest_trio_from_thread_run_contextvars.<locals>.thread_fn.<locals>.async_back_in_main9  sQ      4 8 8 : $$^4!5!9!9!;002f<<<$88s   AAr  )	r  r  r   rq   rr   r  r  r  r   )r  r  r  r  r  r  s         r9   r   8test_trio_from_thread_run_contextvars.<locals>.thread_fn2  s    2668  *3779]]7<<=))+ >	9 1@@R0S-1557]]7<<=))+ >   
 	
 >= >=r  r  r  r  r  r  r  s          r9   %test_trio_from_thread_run_contextvarsr  /  s     V$
@ !++(,,.M9699999V8JVhVVVVV///((*f444 	,r  c                     [         R                  " [        5         [        [        R
                  SS9  S S S 5        g ! , (       d  f       g = f)NzNot TrioTokentyper*   r  rh   rP   r9   4test_run_fn_as_system_task_catched_badly_typed_tokenr  Z  s.    	|	$*	
 
%	$	$s	   =
Ac                    #    SS jn [         R                  " 5       n[        R                  " [        5         [        XS9  S S S 5        g ! , (       d  f       g = f7f)Nc                     [        5       er_   )AssertionErrorrh   rP   r9   
not_called7test_from_thread_inside_trio_thread.<locals>.not_calledc  s    rP   r*   rA   )r   rc   rq   rr   rs   r   )r  r+   s     r9   #test_from_thread_inside_trio_threadr  b  s9      ))+J	|	$Z? 
%	$	$s   5A
A
	A

AAc                    ^^^ / m/ mSU4S jjmSUU4S jjn [         R                  " U S5        [         R                  " U S5        TSS/:X  d   eg )	Nc               l  >#     S 7v   [         R                  " SS9    [        [        [        [
        SU S95      I S h  vN   TR                  S5        S S S 5        g  N! [         R                   a    TR                  S5         N2f = f! , (       d  f       g = f! [         R                  " SS9    [        [        [        [
        SU S95      I S h  vN    TR                  S5        O+! [         R                   a    TR                  S5         Of = fS S S 5        f ! , (       d  f       f = f= f7f)NTr  r   r*   cleanr  )r   r   r    r   r   r   r.   RunFinishedError)rd   r8   s    r9   agen2test_from_thread_run_during_shutdown.<locals>.ageno  s     	+""$/+,eL   MM'* 0/ -- .MM*-. 0/""$/+,eL   MM'* -- .MM*-. 0//s   D4B D4B A! AA!B	D4A!!%B	BB		B
BD4D12D 4 C,C
C,D ,%D	D D	D 	D1 
D.*D11D4c                   >#    TR                  T" U (       a  [        R                  " 5       OS 5      5        TS   R                  S 5      I S h  vN   g  N7f)NrO  )r.   r   rc   asend)use_system_taskr  saves    r9   r   2test_from_thread_run_during_shutdown.<locals>.main}  s:     D113DQR2hnnT"""s   AAAATFr  r  )rd   r`   rB   zAsyncGenerator[None, None])r  r  rB   rC   )r   r   )r   r  r8   r  s    @@@r9   $test_from_thread_run_during_shutdownr  k  sM    DF+# # 
IIdD	IIdEj'****rP   c                    #    [         R                  " 5       n [        U [         R                  5      (       d   e[        R
                  " U 5      nX" 5       L d   eg 7fr_   )r   rc   r  	TrioTokenweakrefref)rd   weak_references     r9   "test_trio_token_weak_referenceabler    sI     $$&EeU__----[['NN$$$$s   AAc                    #     " S S5      n [         R                  " [        5         [        [        U " 5       S9I S h  vN   S S S 5        g  N! , (       d  f       g = f7f)Nc                      \ rS rSrSS jrSrg)4test_unsafe_abandon_on_cancel_kwarg.<locals>.BadBooli  c                    [         er_   )NotImplementedError)rc  s    r9   __bool__=test_unsafe_abandon_on_cancel_kwarg.<locals>.BadBool.__bool__  s    %%rP   rh   NrB   r  )r<  r=  r>  r?  r  rA  rh   rP   r9   BadBoolr    s    	&rP   r  r  )rq   rr   r  r    rb   )r  s    r9   #test_unsafe_abandon_on_cancel_kwargr    sC     & & 
*	+ 	BBB 
,	+B 
,	+s,   %AAAA	AA
AAc                    #    [         R                  " 5       n SS jnU [        [        [         R                  5      I S h  vN L d   eU [        [        U5      I S h  vN L d   eg  N& N7f)Nc                 4   #    [         R                  " 5       $ 7fr_   )r   current_taskrh   rP   r9   async_current_task8test_from_thread_reuses_task.<locals>.async_current_task  s     !!##s   )rB   z
_core.Task)r   r  r    r   r   )taskr  s     r9   test_from_thread_reuses_taskr    s]     D$ +,@%BTBTUUUUU+O=OPPPPP VPs"   =A*A& A*A(
A*(A*c                 X   ^#    S mSU4S jjn T[        U 5      I S h  vN :w  d   eg  N
7f)Nc                 j   > [         R                  " 5       m [        [        [         R                  5      $ r_   )r/   r   r   r    )tids   r9   get_tid_then_reenter6test_recursive_to_thread.<locals>.get_tid_then_reenter  s%    !!#193F3FGGrP   )rB   rb   r   )r   r  s    @r9   test_recursive_to_threadr"    s.     
CH *+?@@@@@@s   *(*c                 
  ^^^#    [         R                  " 5       mS	UU4S jjn [        R                  " 5        m[	        U 5      I S h  vN   S S S 5        TR
                  (       a   eTR                  5       (       a   e[        R                  " 5        m[	        U SS9I S h  vN   S S S 5        TR
                  (       d   e[	        [        TR                  SS95      I S h  vN (       a   eS
S jmS	UUU4S jjn[        R                  " 5        m[	        U5      I S h  vN   S S S 5        TR
                  (       a   eTR                  5       (       a   e[        R                  " 5        m[	        USS9I S h  vN   S S S 5        TR
                  (       d   e[	        [        TR                  SS95      I S h  vN (       a   eS	U4S jjn[        R                  " 5        m[	        [        U5      I S h  vN   S S S 5        TR
                  (       d   eg  GN! , (       d  f       GN= f GN! , (       d  f       GN= f GNa GN%! , (       d  f       GN*= f N! , (       d  f       N= f N Nw! , (       d  f       N{= f7f)Nc                    > [        T R                  5         [        [        5        TR                  S5        g ! [        R
                   a    TR                  S5         g f = fNFT)r   r  r  r  r   r   )r  queues   r9   
sync_check3test_from_thread_host_cancelled.<locals>.sync_check  sL    \001	 & IIe  	IIdO	s   9 %A! A!Tr  r   timeoutc                    #    g7fNTrh   rh   rP   r9   no_checkpoint6test_from_thread_host_cancelled.<locals>.no_checkpoint  s     rp   c                    > [        T R                  5         [        T5      (       d   e TR                  S5        g ! [        R
                   a    TR                  S5         g f = fr%  )r   r  r   r  r   r   )r  r-  r&  s   r9   async_check4test_from_thread_host_cancelled.<locals>.async_check  sU    \001	"=1111 IIe  	IIdO	s   = %A%$A%c                    >#    T R                  5         [        S5         [        5       I S h  vN   S S S 5        g  N! , (       d  f       g = f7f)Nr  )r  r   r   )r  s   r9   async_time_bomb8test_from_thread_host_cancelled.<locals>.async_time_bomb  s5     ^/!! ^! ^s%   A=;=	A=
AArA   r  )
r  r  r   r   r    r  
get_nowaitr   r  r   )r'  r0  r3  r  r-  r&  s      @@@r9   test_from_thread_host_cancelledr6    s    &2&8&8&:E  
			 ,,, 
 ,,,,!!!!				 tDDD 
 (((('		1(EFFFFF  
			 --- 
 ,,,,!!!!				 EEE 
 (((('		1(EFFFFF"
 
			 /BBB 
 ((((W 	- 
	 	E 
	 G 	. 
	 	F 
	 G 	C 
	s   4JHH	HAJH1"H.#H1';J"I#/JI	!I"I	&AJ-I;I<I ;J;I.<(J$I28I09I2=JH
H+&J.H11
I ;	JI		
IJI
I+'J0I22
J <Jc                 H  ^^^^#    [         R                  " 5       mSUU4S jjn SUU4S jjm/ m[        R                  " 5       m[        R
                  " 5        IS h  vN nUR                  U S[        R                  " 5       5        [        5       I S h  vN   TS   S:X  d   eTR                  SS9S:X  d   eTR                  5         S S S 5      IS h  vN   TS   S	:X  d   e/ m[        R                  " 5       m[        R                  " 5       n[        R
                  " 5        IS h  vN nUR                  U SU5        [        5       I S h  vN   TS   S:X  d   eTR                  SS9S:X  d   eUR                  5         TR                  5         S S S 5      IS h  vN   UR                  (       d   eS
T;   d   eTS   S	:X  d   eSUU4S jjm/ m[        R                  " 5       m[        R                  " 5       n[        R
                  " 5        IS h  vN nUR                  U SU5        [        5       I S h  vN   TS   S:X  d   eUR                  5         TR                  5         S S S 5      IS h  vN   UR                  (       d   eS
T;   d   eTS   S	:X  d   eTR                  SS9S:X  d   eg  GN\ GN' GN! , IS h  vN  (       d  f       GN = f GN GN GND! , IS h  vN  (       d  f       GNZ= f N N N! , IS h  vN  (       d  f       N= f7f)Nc                4  >#    U   TR                  S5         [        TU S9I S h  vN TR                  S5        sS S S 5        $  N! [        R                   a    TR                  S5        e f = f! TR                  S5        f = f! , (       d  f       g = f7f)Nr)   r  r  r  )r.   r    r   r   )r  r  r@   r8   s     r9   r  /test_from_thread_check_cancelled.<locals>.child  s{     MM'"&/EVWW
 f% U X?? h' f% UsM   BBAAAB
BA'A..A11BB
BBc                    >  [        5         TR                  S5        T R	                  5         [        5       $ ! [        R                   a    TR                  S5         NAf = fNNot Cancelledr   )r   r  r   r   r   r   r  s   r9   r@   +test_from_thread_check_cancelled.<locals>.f  sO    	#') EE/"
	*,,  	EE+	s   
8 %A A Fr   r)   r   r)  r<  r  r  rO  c                    > T R                  5          [        5         TR                  S5        g ! [        R                   a    TR                  S5         g f = fr;  )r   r   r  r   r   r=  s   r9   r@   r>    sF    
		#') EE/"  	EE+	s   
/ %AATr   )r  r  r  r   rB   rC   rA   )r  r  r/   r   r   r  r  r   r"   r  r   r  r  )r  r  r  r   r@   r  r8   s      @@@@r9    test_from_thread_check_cancelledr@    s    !-!3!3!5A	& 	&- - F		B!!##w5%):):)<=$&&&ayG###uuQu?222
 $# !9 F		BE!!##w5%/$&&&ayG###uuQu?222
 $# !!!!v":# # F		BE!!##w5$.$&&&ayG###
 $# !!!!v":555{***a $& $### $& $###2 $& $###s  AL"J:L""4KJ=4KL"K AL"+K,L"/!K'K!AK'L" K$!A8L"LL"!L>L?/L.L"9L:AL"=K L"K	K
K	L"!K'$L"'K?-K0.K?:	L"LL"LLLL"c                   ^ #    [         R                  " [        5         [        5         S S S 5        [        R
                  " 5       m [        R                  " [        U 4S j5        [         R                  " [        5         T R                  SS9R                  5         S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f7f)Nc                &   > TR                  U 5      $ r_   )r  )r   r  s    r9   ri   Ltest_from_thread_check_cancelled_raises_in_foreign_threads.<locals>.<lambda>;  s    1558rP   r   r)  )
rq   rr   rs   r   r  r  r   r  r  unwrap)r  s   @r9   :test_from_thread_check_cancelled_raises_in_foreign_threadsrE  7  sy     	|	$#% 
%-9-?-?-AA	79KL	|	$	a! 
%	$	 
%	$ 
%	$s4   CB&AC?B7	C&
B40C7
CCc                 >  #    SS jn [        S5         [        R                  " 5        IS h  vN n[        S5       H  nUR	                  U 5        M     S S S 5      IS h  vN   S S S 5        g  N@ N! , IS h  vN  (       d  f       N$= f! , (       d  f       g = f7f)Nc                 L   #     [        [        [        SSS9I S h  vN   M   N7f)Nr   Fr  )r    r   r   rh   rP   r9   r  +test_reentry_doesnt_deadlock.<locals>.childF  s%     $_eQRWXXX Xs   $"$r      rA   )r   r   r  r  r  )r  r  r   s      r9   test_reentry_doesnt_deadlockrJ  @  sg     Y 
q	%%''71X""5)  (' 
	'''' 
	sa   BBA.B$A2B A0!B%	B.B0B2B		8A;9B		B
BBc                 ^  ^#    Sm[        5       n [        5       n[        5       n[        5       nSS jnSU4S jjn[        R                  " 5        IS h  vN nUR                  X@U5        UR                  XAU5        [	        5       I S h  vN   UR                  U5        [	        5       I S h  vN   T(       a   e[        5       S:X  d   eU R                  5         UR                  5       I S h  vN   [	        5       I S h  vN   T(       a   e[        5       S:X  d   eUR                  5         UR                  5       I S h  vN   [	        5       I S h  vN   T(       d   e[        5       S:X  d   eS S S 5      IS h  vN   g  GN. N N N N NK N; N! , IS h  vN  (       d  f       g = f7f)	NFc                h   ^ #    SU 4S jjn[        U5      I S h  vN   UR                  5         g  N7f)Nc                 0   > [        T R                  5        g r_   )r   r   )r   s   r9   r   Ctest_wait_all_threads_completed.<locals>.wait_event.<locals>.threadY  s    AFF#rP   rA   )r    r   )r   e_exitr   s   `  r9   
wait_event3test_wait_all_threads_completed.<locals>.wait_eventX  s)     	$ !(((

 	)s   202c                 :   >#    [        5       I S h  vN   Sm g  N7fr,  )r!   )no_threads_lefts   r9   wait_no_threads_left=test_wait_all_threads_completed.<locals>.wait_no_threads_left_  s     (*** 	+s   r   r   r   )r   r   rO  r   rB   rC   rA   )r   r   r  r  r"   r   r   r   )e1e2	e1_exited	e2_exitedrP  rT  r  rS  s          @r9   test_wait_all_threads_completedrZ  P  sS    O	B	BII
 !!##w:95:95$&&&/0$&&&""""$)))
nn$&&&""""$)))
nn$&&&"$)))' $## 	'&
 	&
 	&# $###s   AF-FF-2F
F"F-F.A F.F	/F FA FFFFF1F-<F=F-FF	FFFFF-F*FF*&F-c                 T   #    [        5       I S h  vN   [        5       S:X  d   eg  N7f)Nr   )r!   r   rh   rP   r9   *test_wait_all_threads_completed_no_threadsr\  z  s'     
$
&&& A%%% 's   (&(rA   r_   )r   z
int | NonerB   r   )r.  zpytest.CaptureFixture[str]r/  pytest.MonkeyPatchrB   rC   )r3  rb   r  r  r5  r  rB   rC   )r/  r]  rB   rC   )d
__future__r   contextvarsr&  r  r   ry   r/   r  r  	functoolsr   typingr   r   r   r	   r
   r   r   r   r   r   rq   r  r   r   r   r   r   r   r   r   r   _core._tests.test_kir   _core._tests.tutilr   _threadsr   r   r   r   r   r    r!   testingr"   outcomer#   lowlevelr$   r   rD   r1   ra   r%   re   rt   r   r   r   r   r   r   r  r   r2  markparametrizerY  rq  r  r  r  r  
ContextVarr  r@  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"  r6  r@  rE  rJ  rZ  r\  rh   rP   r9   <module>rk     sM   "   	 
        	 	 	 + %   -%U9#3#3T-5H#HIIJK
CL9Qx-$`/8#:'E\ 1F@0,6"x#,%#,##, 
#,L 
+E4=1.>q+	q+q+ q+ 
	q+ ? 2 ,q+h,(,8(#(	((	(+ 5@4J4J5 1 
"5J.*;0	(	(1(0V(5V
@+6%CQ	A8)vK+\" * *'*T&rP   