
     f                       U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZ d dlmZmZmZmZmZmZmZmZmZmZ d dlZd dlZddlmZmZmZmZmZmZm Z m!Z! ddl"m#Z# ddl$m%Z% dd	l&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- dd
l.m/Z/ erd dl0m1Z1 ddl2m3Z3 eee4eej5        ee6         f         f                  Z7 ed          Z8dGdZ9dGdZ:dGdZ;dGdZ<dGdZ=dHdIdZ>dGdZ?dGdZ@dGdZAdGdZBdJd!ZCejD        E                    d"g d#          ejD        E                    d$d%d&g          ejD        E                    d'd%d&g          dKd*                                    ZFdGd+ZGdGd,ZHdLd-ZIdGd.ZJdGd/ZK ejL        d0          ZMd1eNd0<   dGd2ZOdGd3ZPdGd4ZQdGd5ZRdGd6ZSdGd7ZTdGd8ZUdGd9ZVdGd:ZWdGd;ZXdGd<ZYdGd=ZZdGd>Z[dGd?Z\dGd@Z]dGdAZ^dGdBZ_dGdCZ`e%dGdD            ZadGdEZbdGdFZcdS )M    )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TreturnNonec                 t  K   t          j                    	 ddfd} t          j                    }dd} | t          |d|           d {V  dd} | t          |dt
          f|           d {V  dd} | t          |d|           d {V  dd} | t          |dt          f|           d {V  d S )Ndo_in_trio_threadCallable[..., threading.Thread]fnCallable[..., T | Awaitable[T]]expectedtuple[str, T]
trio_token_core.TrioToken | Noner&   r'   c                4   K   g d
 fd}t          j        |d          }|                                 |                                r8t	          d           t          d           d {V  |                                8d|fd	f|gk    sJ d S )Nr&   r'   c                 :   	                      dt          j                    f                      }                      d| f           d S # t          $ r>}t	          |                                dt          |          f           Y d }~d S d }~ww xY w)Nstartr/   goterror)append	threadingcurrent_threadBaseExceptionprinttype)xexcr)   r+   recordr/   s     [/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/trio/_tests/test_threads.pythreadfnz<test_do_in_trio_thread.<locals>.check_case.<locals>.threadfnF   s    4w	(@(B(BCDDD%%b&ZHHHuaj)))))  4 4 4c


wS		23333333334s   AA 
B3BBT)targetdaemonyawn{Gz?r3   fr&   r'   )r8   Threadr3   is_aliver;   r   )r)   r+   r-   r/   rA   child_threadr?   trio_threads   `` `  @r@   
check_casez*test_do_in_trio_thread.<locals>.check_case>   s        	4 	4 	4 	4 	4 	4 	4 	4 	4 !'xEEE##%% 	&MMM++ ##%% 	 7L1C3ExPPPPPPP    r?   
RecordTypeintc                    t          j                    rJ |                     dt          j                    f           dS )NrF   r   )r   currently_ki_protectedr7   r8   r9   r?   s    r@   f1z"test_do_in_trio_thread.<locals>.f1X   s<    /11111sI4667888qrM   )r5   r   r4   r   c                    t          j                    rJ |                     dt          j                    f           t
          NrF   )r   rQ   r7   r8   r9   
ValueErrorrR   s    r@   f2z"test_do_in_trio_thread.<locals>.f2_   s=    /11111sI4667888rM   r6   c                   K   t          j                    rJ t          j                     d {V  |                     dt	          j                    f           dS )NrF      )r   rQ   
checkpointr7   r8   r9   rR   s    r@   f3z"test_do_in_trio_thread.<locals>.f3f   sa      /11111         sI4667888qrM   )r5   rY   c                   K   t          j                    rJ t          j                     d {V  |                     dt	          j                    f           t          rU   )r   rQ   rZ   r7   r8   r9   KeyErrorrR   s    r@   f4z"test_do_in_trio_thread.<locals>.f4n   sa      /11111         sI4667888rM   N)
r)   r*   r+   r,   r-   r.   r/   r0   r&   r'   )r?   rN   r&   rO   )r?   rN   r&   r   )r8   r9   r   current_trio_tokenr   rV   r   r]   )rL   tokenrS   rW   r[   r^   rK   s         @r@   test_do_in_trio_threadrb   ;   sk     *,,K .2	Q Q Q Q Q Q Q0 $&&E   
 *)2ze
L
L
LLLLLLLL   
 *)2/DQV
W
W
WWWWWWWW    *_b*
G
G
GGGGGGGG    *_b7H*=%
P
P
PPPPPPPPPPrM   c                   K   t          j        t                    5  t          d            d d d            n# 1 swxY w Y   dd} t          j        t                    5  t	          |            d d d            d S # 1 swxY w Y   d S )Nc                     d S r_    re   rM   r@   <lambda>z9test_do_in_trio_thread_from_trio_thread.<locals>.<lambda>y       T rM   r&   r'   c                 
   K   d S r_   re   re   rM   r@   fooz4test_do_in_trio_thread_from_trio_thread.<locals>.foo{         rM   rG   )pytestraisesRuntimeErrorr   r   )ri   s    r@   'test_do_in_trio_thread_from_trio_threadrn   w   s     	|	$	$ + +\\***+ + + + + + + + + + + + + + +    
|	$	$                   s   9= =!A>>BBc                 l    t                      dfd} t          j        |            ddhk    sJ d S )Nr&   r'   c                   K   t          j                    dddfddfd} t          j        |           }|                                 t          d           |                                r)t          d           d {V  |                                )t          d	           |                                 t          d
           d S )Nr&   r'   c                    t          d           t          j                    rJ t          d           	 t                       dd l} t          d | j                               d S # dd l} t          d | j                               w xY w)Nzin Trio threadr   r   finally)r;   r   rQ   r   sysexc_info)rs   s    r@   trio_thread_fnzTtest_run_in_trio_thread_ki.<locals>.check_run_in_trio_thread.<locals>.trio_thread_fn   s    "###355555)1			


i00000 


i0000s   A& &#B	c                     K                  d S r_   re   )ru   s   r@   trio_thread_afnzUtest_run_in_trio_thread_ki.<locals>.check_run_in_trio_thread.<locals>.trio_thread_afn   s      NrM   c                 B   	 t          d           t                     n4# t          $ r' t          d                                d           Y nw xY w	 t	                     d S # t          $ r( t          d                                d           Y d S w xY w)Nrunningr4   ok1ok2)r;   r   KeyboardInterruptaddr   )r?   ra   rw   ru   s   r@   external_thread_fnzXtest_run_in_trio_thread_ki.<locals>.check_run_in_trio_thread.<locals>.external_thread_fn   s    "i   $^FFFFF$ " " "e

5!!!!!""EBBBBBB$ " " "e

5!!!!!!"s!    $ .AAA, ,.BB)rB   waitingrE   zwaited, joiningdonerG   )	r   r`   r8   rH   r3   r;   rI   r   join)r~   threadra   rw   ru   r?   s     @@@r@   check_run_in_trio_threadz<test_run_in_trio_thread_ki.<locals>.check_run_in_trio_thread   s     (**		1 		1 		1 		1	 	 	 	 	 		" 	" 	" 	" 	" 	" 	" 	" 	" !);<<<ioo 	++ oo 	   frM   rz   r{   rG   )setr   run)r   r?   s    @r@   test_run_in_trio_thread_kir      s[     UUF% % % % % %N 
I&'''eU^######rM   c                     g t                      dfddfddfd} t          j        |           }|                                 d	d
gk    sJ d S )Nr&   r'   c                    K                        d                                             t          j        d            d {V  d S )Nsleepingc                $    t           j        j        S r_   )r   Abort	SUCCEEDED)_s    r@   rf   zMtest_await_in_trio_thread_while_main_exits.<locals>.trio_fn.<locals>.<lambda>   s    EK4I rM   )r7   r   r   wait_task_rescheduled)evr?   s   r@   trio_fnz;test_await_in_trio_thread_while_main_exits.<locals>.trio_fn   sS      j!!!
)*I*IJJJJJJJJJJJrM   ra   _core.TrioTokenc                    	 t          |            d S # t          j        $ r                     d           Y d S w xY w)Nr4   	cancelled)r   r   	Cancelledr7   )ra   r?   r   s    r@   	thread_fnz=test_await_in_trio_thread_while_main_exits.<locals>.thread_fn   sY    	'G666666 	' 	' 	'MM+&&&&&&	's    $>>threading.Threadc                    K   t          j                    } t          j        | f          }|                                                                  d {V  dgk    sJ |S )N)rB   argsr   )r   r`   r8   rH   r3   wait)ra   r   r   r?   r   s     r@   mainz8test_await_in_trio_thread_while_main_exits.<locals>.main   sj      (**!%BBBggii*%%%%rM   r   r   rG   )ra   r   r&   r'   )r&   r   )r   r   r   r   )r   r   r   r?   r   r   s     @@@@r@   *test_await_in_trio_thread_while_main_exitsr      s    F	BK K K K K K K
' ' ' ' ' ' '        Yt__F
KKMMMj+.......rM   c                 ^  K   d} d| z   fdddfd	t                     d {V  t          d 
           d {V  t           d| z                        d {V  dfd} |d           d {V   |d           d {V   |d           d {V   |d           d {V  d S )Nz0 from trio._tests.test_threads.test_named_threadinnernamestrr&   r   c                d    t          j                    j        | k    sJ t          j                    S r_   )r8   r9   r   )r   s    r@   r   z test_named_thread.<locals>.inner   s.    ')).$6666')))rM   "Callable[[None], threading.Thread]c                $    t          |           S r_   r   r   r   s    r@   rF   ztest_named_thread.<locals>.f       ud###rM   thread_namer'   c                   K   t           |           |            d {V }t          j        d|j                  sJ d S )Nr   Trio thread [0-9]*)r    rematchr   )r   r   rF   s     r@   test_thread_namez+test_named_thread.<locals>.test_thread_name   sT      )!!D''tDDDDDDDDDx,fk:::::::rM    fobiedooname_longer_than_15_characters   💙r   r   r&   r   r   r   r&   r   )r   r   r&   r'   r    )endingr   rF   r   s     @@r@   test_named_threadr      sv     ?F!F* * * * * *$ $ $ $ $ $ U
#
########
U
5
5
55555555 QQv//
0
00000000; ; ; ; ; ; 
2



:
&
&&&&&&&&

;
<
<<<<<<<<

6
"
""""""""""rM   ident
int | None
str | Nonec                j   dd l }dd l}|j                            d          }|sd}	 |                    |          }n-# t
          $ r  t          dt          j                    Y d S w xY wt          |dd           }|sJ |j
        |j        |j        g|_        |j        |_        |                    dd          }| t#          j                    }  || |d          dk    sJ 	 |j                                        S # t*          $ r*}t-          j        d	|j        d
|            Y d }~d S d }~ww xY w)Nr   pthreadzlibc.sozno pthread on pthread_getname_nprM      )sizezvalue: z, exception: )ctypesctypes.utilutilfind_libraryCDLL	Exceptionr;   rs   platformgetattrc_void_pc_char_pc_size_targtypesc_intrestypecreate_string_bufferr8   	get_identvaluedecodeUnicodeDecodeErrorrk   fail)r   r   libpthread_path
libpthreadr   name_bufferes          r@   _get_thread_namer      s   MMMk..y99O $ $[[11

   -s|--...tt !-A4HH  	#
 "(--c-;;K}#%%e["55::::E ''))) E E ECk/CCCCDDDDDDDDDEs'   > &A('A(%C> >
D2D--D2c                 <  K   dddfdd} t           |                      d {V  t           |           d 	           d {V  ddfd} |d           d {V   |d           d {V   |d           d {V   |dd           d {V  d S )Nr   r   r&   r   c                    t                      }|2t          j        dk    r"t          j        dt          j                    n|| d d         k    sJ t          j                    S )Nlinuxzno pthread OS support on    )r   rs   r   rk   skipr8   r9   )r   os_thread_names     r@   r   z#test_named_thread_os.<locals>.inner  se    )++!clg&=&=KBCLBBCCCC!T#2#Y....')))rM   r   c                $    t          |           S r_   r   r   s    r@   rF   ztest_named_thread_os.<locals>.f#  r   rM   z4None from trio._tests.test_threads.test_named_threadr   r-   r   r'   c                   K   || }t           |          |            d {V }t          |j                  }|
J d            t          j        d|          sJ d S )Nr   z'should skip earlier if this is the caser   )r    r   r   r   r   )r   r-   r   r   rF   s       r@   r   z.test_named_thread_os.<locals>.test_thread_name,  s      H)!!H++4HHHHHHHHH)&,77))+T)))x,n=======rM   r   r   r   r   ?)r-   r   r   r_   )r   r   r-   r   r&   r'   r   )defaultr   rF   r   s     @@r@   test_named_thread_osr     sT     * * * *$ $ $ $ $ $ EG
QQwZZ
(
((((((((
QQwZZT
:
:
::::::::> > > > > > > 
2



:
&
&&&&&&&&

;
<
<<<<<<<<

6C
0
0
0000000000rM   c                    K   ddl m}   |             }|5t          j        dk    sJ t	          j        dt          j                    d S d S )Nr   )get_os_thread_name_funcr   zno pthread_setname_np on )trio._core._thread_cacher   rs   r   rk   r   )r   ks     r@   test_has_pthread_setname_npr   <  sf      @@@@@@!!Ay|w&&&&>>>????? yrM   c                   K   t          j                    } dd}t          |d           d {V \  }}|dk    sJ || k    sJ dd}t          j        t
          d	
          5 }t          |           d {V  d d d            n# 1 swxY w Y   t          |j        j                   |j        j        d         | k    sJ d S )Nr=   r%   r&   tuple[T, threading.Thread]c                ,    | t          j                    fS r_   )r8   r9   )r=   s    r@   rF   z$test_run_in_worker_thread.<locals>.fH  s    9+--..rM      r   c                 B    t          t          j                              r_   )rV   r8   r9   re   rM   r@   gz$test_run_in_worker_thread.<locals>.gO  s    133444rM   z1^<Thread\(Trio thread \d+, started daemon \d+\)>$r   r   )r=   r%   r&   r   )r&   r   )	r8   r9   r    rk   rl   rV   r;   r   r   )rK   rF   r=   rJ   r   excinfos         r@   test_run_in_worker_threadr   E  sI     *,,K/ / / / /q!44444444OA|6666;&&&&5 5 5 5 
N
 
 
 $	 #########$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 
'-
=a K//////s   "BBBc                   K   d gdfddfd	} g t          j                    }t          j                    4 d {V }|                    | |d
           t                       d {V  dgk    sJ |j                                         d d d           d {V  n# 1 d {V swxY w Y   d         dk    sJ |                    d            d         dk    r t          j
        d           d         dk     g d d<   t          j                    4 d {V }|                    | |d           t                       d {V  |j                                         t          j        d
          5  t          d          D ]}t          j                     d {V  	 d d d            n# 1 swxY w Y   dgk    sJ |                    d            d d d           d {V  n# 1 d {V swxY w Y   t          j                    5 }|                                  | |d           d {V  d d d            n# 1 swxY w Y   |j        sJ d S )Nqstdlib_queue.Queue[str]r&   r'   c                D    dd<   |                                   dd<   d S )Nblockingr   finished)get)r   registers    r@   rF   z1test_run_in_worker_thread_cancellation.<locals>.f]  s&     	 rM   stdlib_queue.Queue[None]abandon_on_cancelboolc                   K                        d           	 t          | |           d {V 	                      d           S #                      d           w xY w)Nr3   r   exit)r7   r    )r   r   rF   r?   s     r@   childz5test_run_in_worker_thread_cancellation.<locals>.childc  ss      g	"+AqDUVVVVVVVVVVMM&!!!!FMM&!!!!s   A ATr3   r   r   rE   Fshield
   )r   r   r&   r'   )r   r   r   r   r&   r'   )stdlib_queueQueuer   open_nursery
start_soonr"   cancel_scopecancelputtimer   r   rangerZ   cancelled_caught)r   r   nurseryr   scoperF   r?   r   s        @@@r@   &test_run_in_worker_thread_cancellationr  Z  sa     "&H! ! ! ! ! !" " " " " " " F"."4"6"6A!## & & & & & & &w5!T*** %&&&&&&&&&'""""##%%%& & & & & & & & & & & & & & & & & & & & & & & & & & & A;*$$$$EE$KKK
1+
#
#
4 1+
#
# FHQK!## 	 	 	 	 	 	 	w5!U+++$&&&&&&&&&##%%%d+++ 	) 	)2YY ) )&(((((((((()	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) '""""	d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 
			 eAuoo               !!!!!!s\   AB$$
B.1B.$AG2>,F7+G27F;	;G2>F;	?!G22
G<?G<'I		IIcapfdpytest.CaptureFixture[str]monkeypatchpytest.MonkeyPatchc                   |                     t          j        dd           t          j                    t          j                    dfddfd}t          j        |                               d                                            }|                                r(t          j
        d           |                                (|                                 \  }}d|vsJ d|vsJ d S )	NIDLE_TIMEOUTrE   r&   r'   c                 |                                                           t          j                               d S r_   )r   r  r8   r9   )q1q2s   r@   r   z6test_run_in_worker_thread_abandoned.<locals>.thread_fn  s1    

y'))*****rM   c                   K   dfd} t          j                    4 d {V }|                    |            t                       d {V  |j                                         d d d           d {V  d S # 1 d {V swxY w Y   d S )Nr&   r'   c                 :   K   t           d           d {V  d S )NTr   r   )r   s   r@   r   z@test_run_in_worker_thread_abandoned.<locals>.main.<locals>.child  s2      $Y$GGGGGGGGGGGGrM   rG   )r   r  r  r"   r  r  )r   r  r   s     r@   r   z1test_run_in_worker_thread_abandoned.<locals>.main  s>     	H 	H 	H 	H 	H 	H %'' 	* 	* 	* 	* 	* 	* 	*7u%%%(********* '')))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   AA99
BBzException in threadrG   )setattrr   _thread_cacher  r  r   r  r   rI   r  r   
readouterr)	r  r  r   r   outerrr  r  r   s	         @@@r@   #test_run_in_worker_thread_abandonedr    s!    +^TBBB#/#5#7#7B/;/A/C/CB+ + + + + + +* * * * * * 
IdOOOFF4LLL VVXXF
//

 
4 //

  !!HC ++++ ++++++rM   MAX)rY      r   r  FTuse_default_limiterrO   r   c                   
K   d| z  }t          j                    
t          j                    |rt                      }|j        }| |_        d nt          |           }| }|	  G d d          d_        d_        d_        d_	        t          j                    d
fd	dfd}t          j                    4 d {V }t          d           g }t          |          D ]S}	|                    t                                 |                    ||d                    t#                       d {V  TrCt          d           |d                                          d {V  t#                       d {V  j	        | k    s|                                j        | k    r=t+          d           d {V  j	        | k     |                                j        | k    =
                                 d d d           d {V  n# 1 d {V swxY w Y   j        | k    sJ r+|j        dk    r t+          d           d {V  |j        dk     j        |k    sJ j        dk    sJ 	 ||_        d S # ||_        w xY w)Nr   c                  8    e Zd ZU ded<   ded<   ded<   ded<   dS )0test_run_in_worker_thread_limiter.<locals>.staterO   ran
high_waterry   parkedN)__name__
__module____qualname____annotations__re   rM   r@   stater$    s4         HHHOOOLLLKKKKKrM   r,  r   r  r   r&   r'   c                   t          d           t          | j                   5  xj        dz  c_        xj        dz  c_        t          j        j                  _        xj        dz  c_        d d d            n# 1 swxY w Y                                    5  xj        dz  c_        xj        dz  c_        d d d            n# 1 swxY w Y   t          d           d S )Nzthread_fn startr4   r   zthread_fn exiting)	r;   r   r  r%  ry   maxr&  r'  r   )r  gatelockr,  ra   s    r@   r   z4test_run_in_worker_thread_limiter.<locals>.thread_fn  sl   #$$$ !4GGGG " "		Q		"#&u'7#G#G  !" " " " " " " " " " " " " " " IIKKK # #!"# # # # # # # # # # # # # # # %&&&&&s$   ABB	B	&!CCCeventr   c                   K   t          j                    5 }t          |           d {V  d d d            n# 1 swxY w Y   t          d|j                   |                                  d S )N)r   limiterzrun_thread finished, cancelled:)r   r   r    r;   r
  r   )r1  r  r  limiter_argr   s     r@   
run_threadz5test_run_in_worker_thread_limiter.<locals>.run_thread  s      "$$ ( &,'	                        3\5RSSSIIKKKKKs   =AAspawningz'waiting for first cancellation to clearrE   )r  r   r&   r'   )r1  r   r&   r'   )r8   r   Lockr   total_tokensr   r%  r&  ry   r'  r   r`   r  r;   r	  r7   r  r"   r   
statisticstasks_waitingr   r   borrowed_tokens)r  r  r!  COUNTcorig_total_tokensr5  r  eventsr   r/  r4  r0  r,  r   ra   s    `        @@@@@@r@   !test_run_in_worker_thread_limiterrA    s      GE?D>D *,,NC  [+	 	 	 	 	 	 	 	 	(**	' 	' 	' 	' 	' 	' 	' 	' 	' 		 		 		 		 		 		 		 		 %'' 	 	 	 	 	 	 	7*F5\\ / /egg&&&"":vbz:::,..........  /?@@@Qinn&&&&&&&&&,......... ##q||~~'Cs'J'JDkk!!!!!!! ##q||~~'Cs'J'J HHJJJ5	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	8 3&&&& 	" #a''Dkk!!!!!!! #a'' yE!!!!}!!!!!******s3   *A&J D3HJ 
HJ "H#AJ 	Jc                    K   g  G fdd          } t          d  |                        d {V  ddgk    sJ d S )Nc                  (    e Zd Zd fdZd fdZdS )	?test_run_in_worker_thread_custom_limiter.<locals>.CustomLimiterborrowerr$   r&   r'   c                D   K                        d           || _        d S Nacquirer7   	_borrowerselfrE  r?   s     r@   acquire_on_behalf_ofzTtest_run_in_worker_thread_custom_limiter.<locals>.CustomLimiter.acquire_on_behalf_of6  s$      MM)$$$%DNNNrM   c                L                         d           || j        k    sJ d S )NreleaserI  rK  s     r@   release_on_behalf_ofzTtest_run_in_worker_thread_custom_limiter.<locals>.CustomLimiter.release_on_behalf_of:  s.    MM)$$$t~------rM   NrE  r$   r&   r'   r(  r)  r*  rM  rP  rR   s   r@   CustomLimiterrD  5  sQ        	& 	& 	& 	& 	& 	&	. 	. 	. 	. 	. 	. 	. 	.rM   rS  c                     d S r_   re   re   rM   r@   rf   z:test_run_in_worker_thread_custom_limiter.<locals>.<lambda>@  rg   rM   r3  rH  rO  r   )rS  r?   s    @r@   (test_run_in_worker_thread_custom_limiterrV  0  s       F. . . . . . . . . . \\==??
C
C
CCCCCCCCi+++++++rM   c                   K   g  G fdd          }  |             }t          j        t          d          5 }t          d |           d {V  d d d            n# 1 swxY w Y   |j        j        J ddgk    sJ g i t          j        t          d          5 }t          fd	|           d {V  d d d            n# 1 swxY w Y   t          |j        j        t                    sJ ddgk    sJ d S )
Nc                  (    e Zd Zd	 fdZd
 fdZdS )Ctest_run_in_worker_thread_limiter_error.<locals>.BadCapacityLimiterrE  r$   r&   r'   c                6   K                        d           d S rG  )r7   rK  s     r@   rM  zXtest_run_in_worker_thread_limiter_error.<locals>.BadCapacityLimiter.acquire_on_behalf_ofH  s      MM)$$$$$rM   r   c                L                         d           t          d          )NrO  zrelease on behalf)r7   rV   rK  s     r@   rP  zXtest_run_in_worker_thread_limiter_error.<locals>.BadCapacityLimiter.release_on_behalf_ofK  s$    MM)$$$0111rM   NrQ  )rE  r$   r&   r   rR  rR   s   r@   BadCapacityLimiterrY  G  sQ        	% 	% 	% 	% 	% 	%	2 	2 	2 	2 	2 	2 	2 	2rM   r\  z^release on behalf$r   c                     d S r_   re   re   rM   r@   rf   z9test_run_in_worker_thread_limiter_error.<locals>.<lambda>R       rM   rU  rH  rO  c                      d         S )Nr=   re   )ds   r@   rf   z9test_run_in_worker_thread_limiter_error.<locals>.<lambda>[  s    3 rM   )rk   rl   rV   r    r   __context__
isinstancer]   )r\  bsr   r`  r?   s      @@r@   'test_run_in_worker_thread_limiter_errorrd  D  s     F2 2 2 2 2 2 2 2 2 2 
			B	z)>	?	?	? ;7 r::::::::::; ; ; ; ; ; ; ; ; ; ; ; ; ; ;=$,,,i+++++F A	z)>	?	?	? =7 <<<<<<<<<<= = = = = = = = = = = = = = =gm/:::::i+++++++s#   A  A$'A$"C		CCc                l  K   dd}|                      t          j        j        d|           t	                      }|j        dk    sJ t          j        t                    5 }t          d	            d {V  d d d            n# 1 swxY w Y   d
t          |j                  v sJ |j        dk    sJ d S )NrL  objectr   r&   r   c                     t          d          )Nz!the engines canna take it captain)rm   )rL  r   s     r@   	bad_startz:test_run_in_worker_thread_fail_to_spawn.<locals>.bad_startd  s    >???rM   start_thread_soonr   c                     d S r_   re   re   rM   r@   rf   z9test_run_in_worker_thread_fail_to_spawn.<locals>.<lambda>n  r^  rM   engines)rL  rf  r   rf  r&   r   )r  r   r  ThreadCacher   r<  rk   rl   rm   r    r   r   )r  rh  r3  r   s       r@   'test_run_in_worker_thread_fail_to_spawnrm  `  s     @ @ @ @ +79LiXXX,..G"a'''' 
|	$	$ / ........./ / / / / / / / / / / / / / /GM******"a''''''s   !BBBc                 r   K   dd} t          j                    }t          |            d {V }||k    sJ d S )Nr&   r   c                 8    t          t          j                  } | S r_   r   r   r`   callee_tokens    r@   r   z5test_trio_to_thread_run_sync_token.<locals>.thread_fnw      +E,DEErM   r&   r   r   r`   r    r   caller_tokenrr  s      r@   "test_trio_to_thread_run_sync_tokenrx  t  `          +--L+I66666666L<''''''rM   c                    K   dd} t          j        t          d          5  t          |            d {V  d d d            d S # 1 swxY w Y   d S )Nr&   r'   c                 
   K   d S r_   re   re   rM   r@   async_fnz=test_trio_to_thread_run_sync_expected_error.<locals>.async_fn  rj   rM   zexpected a sync functionr   rG   )rk   rl   	TypeErrorr    r|  s    r@   +test_trio_to_thread_run_sync_expected_errorr    s          
y(B	C	C	C + + *********+ + + + + + + + + + + + + + + + + +s   AA	A	trio_test_contextvarzcontextvars.ContextVar[str]c                   K   t          j                    } t                              d           d
d}t	          |           d {V \  }}|dk    sJ || k    sJ dd}t	          |           d {V \  }}}t                                          }|dk    sJ |dk    sJ |dk    s
J d            t          j                    d	k    sJ d S )Nr   r&   tuple[str, threading.Thread]c                     t                                           } t          j        t          j                  5  t	          j                     d d d            n# 1 swxY w Y   | t          j                    fS r_   )	r  r   rk   rl   sniffioAsyncLibraryNotFoundErrorcurrent_async_libraryr8   r9   )r   s    r@   rF   z3test_trio_to_thread_run_sync_contextvars.<locals>.f  s    $((**]7<== 	, 	,)+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,y/1122s   AAA!tuple[str, str, threading.Thread]c                 X   t                                           } t                               d           t                                           }t          j        t
          j                  5  t          j                     d d d            n# 1 swxY w Y   | |t          j	                    fS )Nworker)
r  r   r   rk   rl   r  r  r  r8   r9   )parent_valueinner_values     r@   r   z3test_trio_to_thread_run_sync_contextvars.<locals>.g  s    +//11  ****..00]7<== 	, 	,)+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, $&&
 	
s   +BBBr  zRThe contextvar value set on the worker would not propagate back to the main threadtrio)r&   r  )r&   r  )r8   r9   r  r   r    r   r  r  )rK   rF   r   rJ   r   r  r  current_values           r@   (test_trio_to_thread_run_sync_contextvarsr    s0     *,,KV$$$3 3 3 3 !31 5 5555555E<F????;&&&&

 

 

 

 5Gq4I4I.I.I.I.I.I.I+L+|(,,..M6!!!!(""""F"""	 #"" (**f444444rM   c                   K   d	d} t          |            d {V }t          |t                    sJ d
dd
fd}t          j        t
          d          5  t          |           d {V  d d d            d S # 1 swxY w Y   d S )Nr&   floatc                 8    t          t          j                  } | S r_   )r   r   current_time)	trio_times    r@   thread_fn_1z3test_trio_from_thread_run_sync.<locals>.thread_fn_1  s    ();<<	rM   r'   c                 
   K   d S r_   re   re   rM   r@   r|  z0test_trio_from_thread_run_sync.<locals>.async_fn  rj   rM   c                 &    t                      d S r_   )r   r~  s   r@   thread_fn_2z3test_trio_from_thread_run_sync.<locals>.thread_fn_2  s    X&&&&&rM   zexpected a synchronous functionr   )r&   r  rG   )r    rb  r  rk   rl   r}  )r  r  r  r|  s      @r@   test_trio_from_thread_run_syncr    s          )55555555Ii'''''   ' ' ' ' ' ' 
y(I	J	J	J . . ---------. . . . . . . . . . . . . . . . . .s   A<<B B c                   K   g d
fdd
fd} t          |            d {V  ddgk    sJ d
d}t          j        t          d	          5  t          t          |           d {V  d d d            d S # 1 swxY w Y   d S )Nr&   r'   c                 \   K   t          j                                          d           d S )Nback in trio)r   r  r7   rR   s   r@   back_in_trio_fnz2test_trio_from_thread_run.<locals>.back_in_trio_fn  s.      n%%%%%rM   c                 P                         d           t                      d S )N	in thread)r7   r   )r  r?   s   r@   r   z,test_trio_from_thread_run.<locals>.thread_fn  s)    k"""(((((rM   r  r  c                     d S r_   re   re   rM   r@   sync_fnz*test_trio_from_thread_run.<locals>.sync_fn  s    rM   zappears to be synchronousr   rG   )r    rk   rl   r}  r   )r   r  r  r?   s     @@r@   test_trio_from_thread_runr    s:      F& & & & & &) ) ) ) ) ) ) Y
'
''''''''k>22222    
y(C	D	D	D ; ; ':::::::::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s   A;;A?A?c                 r   K   dd} t          j                    }t          |            d {V }||k    sJ d S )Nr&   r   c                 8    t          t          j                  } | S r_   rp  rq  s    r@   r   z.test_trio_from_thread_token.<locals>.thread_fn  rs  rM   rt  ru  rv  s      r@   test_trio_from_thread_tokenr    ry  rM   c                 t   K   dd} t          j                    }t          | |           d {V }||k    sJ d S )Nra   r   r&   c                <    t          t          j        |           }|S )Nr4   rp  )ra   rr  s     r@   r   z4test_trio_from_thread_token_kwarg.<locals>.thread_fn  s    +E,DQVWWWrM   )ra   r   r&   r   ru  rv  s      r@   !test_trio_from_thread_token_kwargr    sb          +--L+I|DDDDDDDDL<''''''rM   c                    K   t          j        t                    5  t          t          j                   d d d            d S # 1 swxY w Y   d S r_   rk   rl   rm   r   r   r  re   rM   r@   test_from_thread_no_tokenr    s       
|	$	$ 1 1U/0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1s   AA
Ac                 B  K   t                               d           dd} t          |            d {V \  }}}}}t                                           }||cxk    rdk    sn J ||cxk    r|cxk    rdk    sn J t	          j                    dk    sJ |dk    sJ d S )	Nr   r&   tuple[str, str, str, str, str]c                 *   t                                           } t                               d           t                                           }t          j        t
          j                  5  t          j                     d d d            n# 1 swxY w Y   dd}t          |          \  }}t                                           }t          j        t
          j                  5  t          j                     d d d            n# 1 swxY w Y   | ||||fS )Nr  r&   tuple[str, str]c                     t                                           } t                               d           t                                           }t          j                    dk    sJ | |fS Nback_in_mainr  r  r   r   r  r  back_parent_valueback_current_values     r@   r  zStest_trio_from_thread_run_sync_contextvars.<locals>.thread_fn.<locals>.back_in_main
  s`     4 8 8 : : $$^444!5!9!9!;!;022f<<<<$&888rM   r&   r  )	r  r   r   rk   rl   r  r  r  r   )thread_parent_valuethread_current_valuer  r  r  thread_after_values         r@   r   z=test_trio_from_thread_run_sync_contextvars.<locals>.thread_fn  s   26688  ***37799]7<== 	, 	,)+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,	9 	9 	9 	9 1E\0R0R--15577]7<== 	, 	,)+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,   
 	
$   +BBB#DD
Dr  r  r  r&   r  r  r   r    r   r  r  r   r  r  r  r  r  r  s          r@   *test_trio_from_thread_run_sync_contextvarsr     s      V$$$
 
 
 
@ !++++++++(,,..M/99996999999#4VVVV8JVVVVhVVVVVV(**f4444//////rM   c                 B  K   t                               d           dd} t          |            d {V \  }}}}}t                                           }||cxk    rdk    sn J ||cxk    r|cxk    rdk    sn J |dk    sJ t	          j                    dk    sJ d S )	Nr   r&   r  c                 *   t                                           } t                               d           t                                           }t          j        t
          j                  5  t          j                     d d d            n# 1 swxY w Y   dd}t          |          \  }}t                                           }t          j        t
          j                  5  t          j                     d d d            n# 1 swxY w Y   | ||||fS )Nr  r&   r  c                    K   t                                           } t                               d           t                                           }t          j                    dk    sJ | |fS r  r  r  s     r@   async_back_in_mainzTtest_trio_from_thread_run_contextvars.<locals>.thread_fn.<locals>.async_back_in_main5  sd       4 8 8 : : $$^444!5!9!9!;!;022f<<<<$&888rM   r  )	r  r   r   rk   rl   r  r  r  r   )r  r  r  r  r  r  s         r@   r   z8test_trio_from_thread_run_contextvars.<locals>.thread_fn.  s   26688  ***37799]7<== 	, 	,)+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,	9 	9 	9 	9 1@@R0S0S--15577]7<== 	, 	,)+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,   
 	
r  r  r  r  r  r  r  s          r@   %test_trio_from_thread_run_contextvarsr  +  s      V$$$
 
 
 
@ !++++++++(,,..M/99996999999#4VVVV8JVVVVhVVVVVV////(**f444444rM   c                     t          j        t                    5  t          t          j        d           d d d            d S # 1 swxY w Y   d S )NzNot TrioTokentyper4   r  re   rM   r@   4test_run_fn_as_system_task_catched_badly_typed_tokenr  V  s    	|	$	$ 
 
*	
 	
 	
 	

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   AA
Ac                    K   dd} t          j                    }t          j        t                    5  t          | |           d d d            d S # 1 swxY w Y   d S )Nr&   r'   c                     t                      r_   )AssertionErrorre   rM   r@   
not_calledz7test_from_thread_inside_trio_thread.<locals>.not_called_  s    rM   r4   rG   )r   r`   rk   rl   rm   r   )r  r/   s     r@   #test_from_thread_inside_trio_threadr  ^  s          )++J	|	$	$ @ @ZJ????@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @s   AAAc                     g g dfddfd	} t          j        | d
           t          j        | d           ddgk    sJ d S )Nra   r0   r&   AsyncGenerator[None, None]c                 K   	 d W V  t          j        d          5  	 t          t          t          t
          d|                      d {V                      d           n*# t           j        $ r                     d           Y nw xY wd d d            d S # 1 swxY w Y   d S # t          j        d          5  	 t          t          t          t
          d|                      d {V                      d           n*# t           j        $ r                     d           Y nw xY wd d d            w # 1 swxY w Y   w xY w)NTr   r   r4   cleanr   )r   r   r    r   r   r   r7   RunFinishedError)ra   r?   s    r@   agenz2test_from_thread_run_during_shutdown.<locals>.agenk  s0     	+EEEE"$/// + ++,eLLL         MM'**** - . . .MM*-----.+ + + + + + + + + + + + + + + + + +"$/// + ++,eLLL         MM'**** - . . .MM*-----.+ + + + + + + + + + + + + + + +s   B+ B0A'B'$BBBBB"%B"+ED?0D	3D?	$D0	-D?/D0	0D?3E?EEEEuse_system_taskr   r'   c                   K                         | rt          j                    nd                      d                             d            d {V  d S )Nr7  )r7   r   r`   asend)r  r  saves    r@   r   z2test_from_thread_run_during_shutdown.<locals>.mainy  sd      DDP1333DQQRRR2hnnT"""""""""""rM   TFr   r  )ra   r0   r&   r  )r  r   r&   r'   )r   r   )r   r  r?   r  s    @@@r@   $test_from_thread_run_during_shutdownr  g  s    DF+ + + + + +# # # # # # # 
IdD	IdEj'*******rM   c                    K   t          j                    } t          | t           j                  sJ t	          j        |           }|  |            u sJ d S r_   )r   r`   rb  	TrioTokenweakrefref)ra   weak_references     r@   "test_trio_token_weak_referenceabler    sZ      $&&EeU_-----[''NNN$$$$$$$$rM   c                    K    G d d          } t          j        t                    5  t          t           |                        d {V  d d d            d S # 1 swxY w Y   d S )Nc                      e Zd ZddZdS )4test_unsafe_abandon_on_cancel_kwarg.<locals>.BadBoolr&   r   c                    t           r_   )NotImplementedError)rL  s    r@   __bool__z=test_unsafe_abandon_on_cancel_kwarg.<locals>.BadBool.__bool__  s    %%rM   Nr&   r   )r(  r)  r*  r  re   rM   r@   BadBoolr    s(        	& 	& 	& 	& 	& 	&rM   r  r   )rk   rl   r  r    rO   )r  s    r@   #test_unsafe_abandon_on_cancel_kwargr    s      & & & & & & & & 
*	+	+ C C 		BBBBBBBBBBC C C C C C C C C C C C C C C C C Cs   %AA"Ac                    K   t          j                    } dd}| t          t          t           j                   d {V u sJ | t          t          |           d {V u sJ d S )Nr&   
_core.Taskc                 ,   K   t          j                    S r_   )r   current_taskre   rM   r@   async_current_taskz8test_from_thread_reuses_task.<locals>.async_current_task  s      !###rM   )r&   r  )r   r  r    r   r   )taskr  s     r@   test_from_thread_reuses_taskr    s      D$ $ $ $ +,@%BTUUUUUUUUUUUU+O=OPPPPPPPPPPPPPPrM   c                 R   K   d dfd} t          |            d {V k    sJ d S )Nr&   rO   c                 h    t          j                     t          t          t           j                  S r_   )r8   r   r   r    )tids   r@   get_tid_then_reenterz6test_recursive_to_thread.<locals>.get_tid_then_reenter  s%    !##193FGGGrM   )r&   rO   r   )r  r  s    @r@   test_recursive_to_threadr    se      
CH H H H H H *+?@@@@@@@@@@@@@@rM   c                 Z  K   t          j                    dfd} t          j                    5 t	          |            d {V  d d d            n# 1 swxY w Y   j        rJ                                 rJ t          j                    5 t	          | d           d {V  d d d            n# 1 swxY w Y   j        sJ t	          t          j        d                     d {V rJ dd	dfd
}t          j                    5 t	          |           d {V  d d d            n# 1 swxY w Y   j        rJ                                 rJ t          j                    5 t	          |d           d {V  d d d            n# 1 swxY w Y   j        sJ t	          t          j        d                     d {V rJ dfd}t          j                    5 t	          t          |           d {V  d d d            n# 1 swxY w Y   j        sJ d S )Nr&   r'   c                     t           j                   	 t          t                                         d           d S # t          j        $ r                     d           Y d S w xY wNFT)r   r  r   r  r   r   )r  queues   r@   
sync_checkz3test_from_thread_host_cancelled.<locals>.sync_check  su    \0111	 &&& IIe  	 	 	IIdOOOOOO	s   A $A*)A*Tr   r   timeoutr   c                 
   K   dS NTre   re   rM   r@   no_checkpointz6test_from_thread_host_cancelled.<locals>.no_checkpoint  s      trM   c                     t           j                   	 t                    sJ 	                     d           d S # t          j        $ r                     d           Y d S w xY wr  )r   r  r   r  r   r   )r  r  r  s   r@   async_checkz4test_from_thread_host_cancelled.<locals>.async_check  s~    \0111	"=111111 IIe  	 	 	IIdOOOOOO	s   A   $A('A(c                    K                                      t          d          5  t                       d {V  d d d            d S # 1 swxY w Y   d S )Nr   )r  r   r   )r  s   r@   async_time_bombz8test_from_thread_host_cancelled.<locals>.async_time_bomb  s      ^^ 	" 	"//!!!!!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   A		AArG   r  )
r  r  r   r   r    r
  
get_nowaitr   r   r   )r  r  r  r  r  r  s      @@@r@   test_from_thread_host_cancelledr     sP     &2&8&:&:E       
			 - ,,,,,,,,,- - - - - - - - - - - - - - - ,,,,!!!!!				 E tDDDDDDDDDDE E E E E E E E E E E E E E E (((('	1(E(E(EFFFFFFFFFFF           
			 . ---------. . . . . . . . . . . . . . . ,,,,!!!!!				 F EEEEEEEEEEF F F F F F F F F F F F F F F (((('	1(E(E(EFFFFFFFFFFF" " " " " "
 
			 C /BBBBBBBBBC C C C C C C C C C C C C C C ((((((sY   AAAB66B:=B:D66D:=D:3FFF/HHHc                   K   t          j                    dfd} dfdg t          j                    t	          j                    4 d {V }|                    | d	t	          j                               t                       d {V  d
         dk    sJ 	                    d          dk    sJ 
                                 d d d           d {V  n# 1 d {V swxY w Y   d         dk    sJ g t          j                    t	          j                    }t	          j                    4 d {V }|                    | d	|           t                       d {V  d
         dk    sJ 	                    d          dk    sJ |                                 
                                 d d d           d {V  n# 1 d {V swxY w Y   |j        sJ dv sJ d         dk    sJ dfdg t          j                    t	          j                    }t	          j                    4 d {V }|                    | d|           t                       d {V  d
         dk    sJ |                                 
                                 d d d           d {V  n# 1 d {V swxY w Y   |j        sJ dv sJ d         dk    sJ 	                    d          dk    sJ d S )Nr   r   r  r   r&   r'   c                L  K   |5                       d           	 t          |            d {V 	                      d           cd d d            S # t          j        $ r                      d            w xY w#                      d           w xY w# 1 swxY w Y   d S )Nr3   r   r   r  )r7   r    r   r   )r   r  rF   r?   s     r@   r   z/test_from_thread_check_cancelled.<locals>.child  s      	& 	&MM'"""&/EVWWWWWWWWWW
 f%%%	& 	& 	& 	& 	& 	& 	& 	& ?   h''' f%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s3   BAB&A<<A??BBB Bc                     	 t                                           d           n*# t          j        $ r                     d           Y nw xY w                                  t                      S NNot Cancelledr   )r   r  r   r   r   r   r   s   r@   rF   z+test_from_thread_check_cancelled.<locals>.f  s}    	#'))) EE/""""  	 	 	EE+	 				*,,,s   ' $AAFr   r3   r   r  r  r   r  r7  c                                                        	 t                                           d           d S # t          j        $ r                     d           Y d S w xY wr  )r   r   r  r   r   r  s   r@   rF   z+test_from_thread_check_cancelled.<locals>.f  su    
				#'))) EE/"""""  	 	 	EE+	s   < $A$#A$Tr   )r   r   r  r   r&   r'   rG   )r  r  r8   r   r   r  r  r   r"   r   r   r  r
  )r   r  r  r   rF   r   r?   s      @@@@r@    test_from_thread_check_cancelledr    s     !-!3!5!5A	& 	& 	& 	& 	& 	& 	&- - - - - - - F			B!##       w5%):)<)<===$&&&&&&&&&ayG####uuQu?2222
                           !9 F			BE!##       w5%///$&&&&&&&&&ayG####uuQu?2222
                           !!!!v":# # # # # # # F			BE!##       w5$...$&&&&&&&&&ayG####
                           !!!!v":555{******s9   A;C##
C-0C-A>G
G G	A"J==
K
Kc                    K   t          j        t                    5  t                       d d d            n# 1 swxY w Y   t	          j                     t          j        t           fd           t          j        t                    5                       d          	                                 d d d            d S # 1 swxY w Y   d S )Nc                .                         |           S r_   )r  )r   r   s    r@   rf   zLtest_from_thread_check_cancelled_raises_in_foreign_threads.<locals>.<lambda>7  s    15588 rM   r   r  )
rk   rl   rm   r   r  r  r   ri  r   unwrap)r   s   @r@   :test_from_thread_check_cancelled_raises_in_foreign_threadsr  3  s8     	|	$	$ & &#%%%& & & & & & & & & & & & & & &-9-?-A-AA	79K9K9K9KLLL	|	$	$ " "	a!!!" " " " " " " " " " " " " " " " " "s   8<<)CC	Cc                 ,  K   dd} t          d          5  t          j                    4 d {V }t          d          D ]}|                    |            	 d d d           d {V  n# 1 d {V swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr&   r'   c                 P   K   	 t          t          t          dd           d {V  $)NTr   Fr   )r    r   r   re   rM   r@   r   z+test_reentry_doesnt_deadlock.<locals>.childB  s<      	Y$_eQRWXXXXXXXXXX	YrM   r      rG   )r   r   r  r	  r  )r   r  r   s      r@   test_reentry_doesnt_deadlockr  <  s~     Y Y Y Y 
q		 * *%'' 	* 	* 	* 	* 	* 	* 	*71XX * *""5))))*	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	** * * * * * * * * * * * * * * * * *s4   B	(A+B	+
A5	5B	8A5	9B		BBc                   K   dt                      } t                      }t                      }t                      }dd}dfd}t          j                    4 d {V }|                    || |           |                    |||           t	                       d {V  |                    |           t	                       d {V  rJ t                      d	k    sJ |                                  |                                 d {V  t	                       d {V  rJ t                      d
k    sJ |                                 |                                 d {V  t	                       d {V  sJ t                      dk    sJ 	 d d d           d {V  d S # 1 d {V swxY w Y   d S )NFr   r   e_exitr&   r'   c                j    K   d fd}t          |           d {V  |                                 d S )Nr&   r'   c                 0    t           j                   d S r_   )r   r   )r   s   r@   r   zCtest_wait_all_threads_completed.<locals>.wait_event.<locals>.threadU  s    AF#####rM   rG   )r    r   )r   r  r   s   `  r@   
wait_eventz3test_wait_all_threads_completed.<locals>.wait_eventT  sX      	$ 	$ 	$ 	$ 	$ 	$ !(((((((((

rM   c                 8   K   t                       d {V  d d S r  )r!   )no_threads_lefts   r@   wait_no_threads_leftz=test_wait_all_threads_completed.<locals>.wait_no_threads_left[  s.      (*********rM   r   r   r   )r   r   r  r   r&   r'   rG   )r   r   r  r  r"   r   r   r   )e1e2	e1_exited	e2_exitedr  r  r  r  s          @r@   test_wait_all_threads_completedr  L  s     O	B	BII        
 !## * * * * * * *w:r9555:r9555$&&&&&&&&&/000$&&&&&&&&&"""""$$))))
nn$&&&&&&&&&"""""$$))))
nn$&&&&&&&&&"$$)))))'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *s   !D8F--
F7:F7c                 Z   K   t                       d {V  t                      dk    sJ d S )Nr   )r!   r   re   rM   r@   *test_wait_all_threads_completed_no_threadsr  v  sA      
$
&
&&&&&&&&  A%%%%%%rM   rG   r_   )r   r   r&   r   )r  r  r  r  r&   r'   )r  rO   r  r   r!  r   r&   r'   )r  r  r&   r'   )d
__future__r   contextvarsr  r  r   rs   r8   r  r  	functoolsr   typingr   r   r   r	   r
   r   r   r   r   r   rk   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   rH   r:   rN   r%   rb   rn   r   r   r   r   r   r   r   r  r  markparametrizerA  rV  rd  rm  rx  r  
ContextVarr  r+  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  re   rM   r@   <module>r-     s1   " " " " " " "         				 



                                     	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 + * * * * * % % % % % %                  - , , , , ,  %U9#3T-5H#HIIJK
GCLL9Q 9Q 9Q 9Qx   -$ -$ -$ -$`/ / / /8# # # #:'E 'E 'E 'E 'E\ 1  1  1  1F@ @ @ @0 0 0 0*6" 6" 6" 6"x", ", ", ",J 


++E4=11.>>o+ o+ o+ ?> 21 ,+o+d, , , ,(, , , ,8( ( ( ((	( 	( 	( 	(+ + + + 5KK4J5 5     
"5 "5 "5 "5J. . . .*; ; ; ;0	( 	( 	( 	(	( 	( 	( 	(1 1 1 1(0 (0 (0 (0V(5 (5 (5 (5V
 
 
 
@ @ @ @+ + + +6% % % %C C C CQ Q Q Q	A 	A 	A 	A8) 8) 8) 8)vK+ K+ K+ K+\" " " " * * * *'* '* '* '*T& & & & & &rM   