+
    Bi                         ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIH	t	H
t
HtHt ^ RIHt ^ RIHtHtHtHt ^ RIHt ^ RIHt ^ RItRt ^ RIHt ^ R	IHt ^ R
IHtHtHt R t!] PD                  ! ]PF                  R8g  ;'       d'    ]PF                  R8g  ;'       d    ]PF                  R8g  R4      t$R t%R t&R t' ! R R] PP                  4      t)]*R8X  d   ] PV                  ! 4        R# R#   ] d    ] P@                  ! R4      hi ; i)    N)	staggered
taskgroupsbase_eventstasks)ANY)	os_helperSHORT_TIMEOUT
busy_retryrequires_gil_enabled)make_script)find_unused_portF)PROCESS_VM_READV_SUPPORTED)RemoteUnwinder)	FrameInfoCoroInfoTaskInfoz2Test only runs when _remote_debugging is availablec                 H    \        WV4      p\        P                  ! 4        V# N)r   	importlibinvalidate_caches)
script_dirscript_basenamesource	to_returns   &&& 4/usr/lib/python3.14/test/test_external_inspection.py_make_test_scriptr   "   s     J@I!    darwinlinuxwin32z*Test only runs on Linux, Windows and MacOSc                 >    \        V R R R7      pVP                  4       # )T)all_threadsdebug)r   get_stack_tracepidunwinders   & r   r$   r$   2   s    ct4@H##%%r   c                 <    \        V R R7      pVP                  4       # T)r#   )r   get_async_stack_tracer%   s   & r   r*   r*   7   s    c.H))++r   c                 <    \        V R R7      pVP                  4       # r)   )r   get_all_awaited_byr%   s   & r   r,   r,   <   s    c.H&&((r   c                     a  ] tR t^At o Rt]]P                  ! ]P                  R8H  ;'       d    ]
'       * R4      R 4       4       t]]P                  ! ]P                  R8H  ;'       d    ]
'       * R4      R 4       4       t]]P                  ! ]P                  R8H  ;'       d    ]
'       * R4      R 4       4       t]]P                  ! ]P                  R8H  ;'       d    ]
'       * R4      R 4       4       t]]P                  ! ]P                  R8H  ;'       d    ]
'       * R4      R 4       4       t]]P                  ! ]P                  R8H  ;'       d    ]
'       * R4      R	 4       4       t]]P                  ! ]P                  R8H  ;'       d    ]
'       * R4      R
 4       4       t]]P                  ! ]P                  R8H  ;'       d    ]
'       * R4      ]! R4      R 4       4       4       tRtV tR# )TestGetStackTraceNr   z5Test only runs on Linux with process_vm_readv supportc           
     0   \        4       p\        P                  ! R V R24      pRp\        P                  ! 4       ;_uu_ 4       p\
        P                  P                  VR4      p\
        P                  ! V4       \        P                  ! \        P                  \        P                  4      pVP                  \        P                  \        P                  ^4       VP                  RV34       VP!                  \"        4       VP%                  ^4       \'        VRV4      pRp \(        P*                  ! \,        P.                  V.4      p	VP1                  4       w  rVP3                  4        RpRV9  g   RV9  d   WP5                  R	4      ,          pK'  \7        V	P8                  4      pVe   VP3                  4        X	P?                  4        V	PA                  4        V	PC                  \"        R7       \E        V^R.4      \E        V^R.4      \E        V^	R.4      \E        \F        PH                  \J        R.4      .pV PM                  \J        V3V4       \E        V^R.4      pV F  w  rW9   g   K   M	  V PO                  R4       RRR4       R#   \:         d    T P=                  R
4        ELi ; i  Te   TP3                  4        X	P?                  4        T	PA                  4        T	PC                  \"        R7       i ; i  + '       g   i     R# ; i)z            import time, sys, socket, threading
            # Connect to the test process
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect(('localhost', a  ))

            def bar():
                for x in range(100):
                    if x == 50:
                        baz()

            def baz():
                foo()

            def foo():
                sock.sendall(b"ready:thread\n"); time.sleep(10_000)  # same line number

            t = threading.Thread(target=bar)
            t.start()
            sock.sendall(b"ready:main\n"); t.join()  # same line number
            N
script_pkg	localhostscriptr   s
   ready:mains   ready:thread   0Insufficient permissions to read the stack tracetimeoutfoobazbarz
Thread.runz<module>z+Main thread stack trace not found in result)(r   textwrapdedentr   temp_dirospathjoinmkdirsocketAF_INETSOCK_STREAM
setsockopt
SOL_SOCKETSO_REUSEADDRbind
settimeoutr	   listenr   
subprocessPopensys
executableacceptcloserecvr$   r&   PermissionErrorskipTestkill	terminatewaitr   	threading__file__r   assertInfail)selfportr2   stack_tracework_dirr   server_socketscript_nameclient_socketp_responsethread_expected_stack_traceframestacks   &              r   test_remote_stack_trace)TestGetStackTrace.test_remote_stack_traceD   s     !( )-v .	
. !!Xh=JHHZ  #MM&..&:L:LMM$$V%6%68K8KQOT23$$]3  #+J&IK M.$$cnnk%BC#0#7#7#9 ##%!1&h6 2 24 88H-aee4 !,!'')}- ;E23;E23;5129--sLAB	+' MM3 ;<kJ {B
;<E'> ( 		GHg "!0 # F
 !,!'')}-C "!!sF   C!L&BJ,CL3LJ2.J51J22J55ALLL	c                t  a \        4       p\        P                  ! R V R24      pRpR EFV  pV P                  VR7      ;_uu_ 4        \        P
                  ! 4       ;_uu_ 4       p\        P                  P                  VR4      p\        P                  ! V4       \        P                  ! \        P                  \        P                  4      pVP                  \        P                  \        P                  ^4       VP!                  RV34       VP#                  \$        4       VP'                  ^4       \)        VRVP+                  VR7      4      pRp	 \,        P.                  ! \0        P2                  V.4      p
VP5                  4       w  rVP7                  4        V	P9                  R4      pV P;                  VR	4       \=        V
P>                  4      pV	e   V	P7                  4        X
PE                  4        V
PG                  4        V
PI                  \$        R7       V^ ,          PJ                   Uu. uF  qPL                  NK  	  ppR F  pV PO                  W4       K  	  V^ ,          PJ                   Uu/ uF  qPP                  VbK  	  upoV^ ,          PJ                   Uu/ uF-  pVPL                  \S        V3R lVPJ                   4       4      bK/  	  ppV P;                  VR0 RmR\S        4       RR0RR0/4       V^ ,          PJ                   Uu/ uF*  pVPL                  \U        R VPV                   4       4      bK,  	  ppV P;                  VR\Y        \Z        P\                  \^        R.4      \Y        \Z        P\                  \^        R.4      \Y        V^R.4      3.R\Y        V^
R.4      \Y        V^R.4      \Y        V^R.4      \Y        V^R.4      3.R\Y        V^R.4      3.R\Y        V^R.4      3./4       V^ ,          PJ                   Uu/ uF-  pVPL                  \U        V3R lVPJ                   4       4      bK/  	  ppV P;                  VR. RR\Y        \Z        P\                  \^        R.4      \Y        \Z        P\                  \^        R.4      \Y        V^R.4      33R\Y        V^R.4      33R\Y        V^R.4      33.RR\Y        \Z        P\                  \^        R.4      \Y        \Z        P\                  \^        R.4      \Y        V^R.4      33.RR\Y        \Z        P\                  \^        R.4      \Y        \Z        P\                  \^        R.4      \Y        V^R.4      33./4       RRR4       RRR4       EKY  	  R#   \@         d    T PC                  R
4        ELi ; i  T	e   T	P7                  4        X
PE                  4        T
PG                  4        T
PI                  \$        R7       i ; iu upi u upi u upi u upi u upi   + '       g   i     L; i  + '       g   i     EK  ; i)            import asyncio
            import time
            import sys
            import socket
            # Connect to the test process
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect(('localhost', a  ))

            def c5():
                sock.sendall(b"ready"); time.sleep(10_000)  # same line number

            async def c4():
                await asyncio.sleep(0)
                c5()

            async def c3():
                await c4()

            async def c2():
                await c3()

            async def c1(task):
                await task

            async def main():
                async with asyncio.TaskGroup() as tg:
                    task = tg.create_task(c2(), name="c2_root")
                    tg.create_task(c1(task), name="sub_main_1")
                    tg.create_task(c1(task), name="sub_main_2")

            def new_eager_loop():
                loop = asyncio.new_event_loop()
                eager_task_factory = asyncio.create_eager_task_factory(
                    asyncio.Task)
                loop.set_task_factory(eager_task_factory)
                return loop

            asyncio.run(main(), loop_factory={TASK_FACTORY})
            N)task_factory_variantr0   r1   r2   )TASK_FACTORYr3      readyr4   r5   c2_root
sub_main_1
sub_main_2c              3   ^   <"   T F"  pSVP                   ,          P                   x  K$  	  R # 5ir   	task_name.0awaited
id_to_tasks   & r   	<genexpr>BTestGetStackTrace.test_async_remote_stack_trace.<locals>.<genexpr>   s)      ('6G #7#4#45??'6   *-Task-1c              3      "   T FE  p\         ;QJ d    . R  VP                   4       F  NK  	  5M! R  VP                   4       4      x  KG  	  R# 5i)c              3   8   "   T F  p\        V4      x  K  	  R # 5ir   tupleru   re   s   & r   rx   LTestGetStackTrace.test_async_remote_stack_trace.<locals>.<genexpr>.<genexpr>       HueEll   Nr   
call_stackru   coros   & r   rx   ry     s;      +$8D HHHHHH$8
   A=ATaskGroup._aexitTaskGroup.__aexit__mainc5c4c3c2c1c              3      <"   T Fb  pSVP                   ,          P                   \        ;QJ d    . R  VP                   4       F  NK  	  5M! R  VP                   4       4      3x  Kd  	  R# 5i)c              3   8   "   T F  p\        V4      x  K  	  R # 5ir   r~   r   s   & r   rx   r   @  s     !LO5%,,Or   Nrs   r   r   ru   r   rw   s   & r   rx   ry   =  sT      +
 %4D 't~~6@@!E!LDOO!LEE!LDOO!LL %4
   +A->A-)zasyncio.new_event_loopnew_eager_loop)rn   ro   rp   >   ro   rp   r{   )0r   r:   r;   subTestr   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   r	   rI   r   formatrJ   rK   rL   rM   rN   rO   rP   assertEqualr*   r&   rQ   rR   rS   rT   rU   
awaited_byrs   rX   task_idsetsortedcoroutine_stackr   r   rW   r   )rZ   r[   r2   r\   rk   r]   r   r^   r_   r`   ra   rb   rc   tasktasks_namesrs   task_name_to_awaited_bycoroutine_stacksawaited_by_coroutine_stacksrw   s   &                  @r   test_async_remote_stack_trace/TestGetStackTrace.test_async_remote_stack_trace   sL     !( )-v  .')
T $N 2FGG""$$WW\\(LA
$ &NNF$6$6! ((%%v':':A ""K#67((7$$Q'/MM/CMD
 !%2"((#..+)FGA'4';';'=$M!''),11$7H$$Xx8"7">K %0%++-FFHKKMFF=F1 0;1~/H/H/HtNN/H   "IIMM)9 "I
 4?q>3L3L3L4LL$&3L
 !,A 9 9+
 !:	 NNC ('+( %  !: ( +   +!#I #%$xj$xj	  !,A 9 9$
 !:	 NNF +$($8$8+ %  !: ! $   $  %(2(;(;(+(:%&!" !&(2(;(;(+(=%&!" !&{B&? @#& " %{B&= > %{B&= > %{B&= > %{B&= >	$ %{B.E(F'H&I${B.E(F'H&I;!X !,A 9 9	/ !: NNF +
 %)OO+ %  !: , 	/   / "! ($),6,?,?,/,>)*%& %*,6,?,?,/,A)*%& %*;F*C$D!"( *E;D2I,J+LM)E;D2I,J+LM-$0 % ($),6,?,?,/,>)*%& %*,6,?,?,/,A)*%& %*;F*C$D!"', % ($),6,?,?,/,>)*%& %*,6,?,?,/,A)*%& %*;F*C$D!"'aFIo % HG %O: ' MMJ
 %0%++-FFHKKMFF=F1+$$V	/[ %$ HGGs   X%&C1XB V
AX7W91X<W>X)3X=X0X	CX3X
D&X0X%V'#V*
&V''V*
*AW66XX"X%%X7c                   \        4       p\        P                  ! R V R24      pRp\        P                  ! 4       ;_uu_ 4       p\
        P                  P                  VR4      p\
        P                  ! V4       \        P                  ! \        P                  \        P                  4      pVP                  \        P                  \        P                  ^4       VP                  RV34       VP!                  \"        4       VP%                  ^4       \'        VRV4      pRp \(        P*                  ! \,        P.                  V.4      p	VP1                  4       w  rVP3                  4        VP5                  R4      pV P7                  VR4       \9        V	P:                  4      pVe   VP3                  4        X	PA                  4        V	PC                  4        V	PE                  \"        R	7       V P7                  \G        V^ ,          PH                  4      ^4       V^ ,          PH                  ^ ,          pV P7                  VPJ                  R
4       \M        R VPN                   4       4      pV P7                  V\Q        V^
R.4      \Q        V^R.4      \Q        V^R.4      3.4       V P7                  VPH                  . 4       RRR4       R#   \<         d    T P?                  R4        ELGi ; i  Te   TP3                  4        X	PA                  4        T	PC                  4        T	PE                  \"        R	7       i ; i  + '       g   i     R# ; i)rj   a  ))

            async def gen_nested_call():
                sock.sendall(b"ready"); time.sleep(10_000)  # same line number

            async def gen():
                for num in range(2):
                    yield num
                    if num == 1:
                        await gen_nested_call()

            async def main():
                async for el in gen():
                    pass

            asyncio.run(main())
            Nr0   r1   r2   r3   rm   r4   r5   r{   c              3      "   T FE  p\         ;QJ d    . R  VP                   4       F  NK  	  5M! R  VP                   4       4      x  KG  	  R# 5i)c              3   8   "   T F  p\        V4      x  K  	  R # 5ir   r~   r   s   & r   rx   OTestGetStackTrace.test_asyncgen_remote_stack_trace.<locals>.<genexpr>.<genexpr>  s     @ueEllr   Nr   r   s   & r   rx   ETestGetStackTrace.test_asyncgen_remote_stack_trace.<locals>.<genexpr>  s;      %0D @@@@@@0r   gen_nested_callgenr   ))r   r:   r;   r   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   r	   rI   r   rJ   rK   rL   rM   rN   rO   rP   r   r*   r&   rQ   rR   rS   rT   rU   lenr   rs   r   r   r   )rZ   r[   r2   r\   r]   r   r^   r_   r`   ra   rb   rc   r   r   s   &             r    test_asyncgen_remote_stack_trace2TestGetStackTrace.test_asyncgen_remote_stack_trace  s     !( )-v .
4 !!Xh=JHHZ "MM&..&:L:LMM$$V%6%68K8KQOT23$$]3  #+J&IK M.$$cnnk%BC#0#7#7#9 ##%(--d3  843AEE: !,!'')}- SQ!:!:;Q?q>,,Q/DT^^X6 % % 00% O  {B0ABC{B67{B78	 T__b1g "!$ # F
 !,!'')}-7 "!!s@   C!M &B K&DM K.*K1-K..K11AL==M  M	c                  a \        4       p\        P                  ! R V R24      pRp\        P                  ! 4       ;_uu_ 4       p\
        P                  P                  VR4      p\
        P                  ! V4       \        P                  ! \        P                  \        P                  4      pVP                  \        P                  \        P                  ^4       VP                  RV34       VP!                  \"        4       VP%                  ^4       \'        VRV4      pRp \(        P*                  ! \,        P.                  V.4      p	VP1                  4       w  rVP3                  4        VP5                  R4      pV P7                  VR4       \9        V	P:                  4      pVe   VP3                  4        X	PA                  4        V	PC                  4        V	PE                  \"        R	7       V^ ,          PF                   Uu. uF  qPH                  NK  	  ppR F  pV PK                  W4       K  	  V^ ,          PF                   Uu/ uF  qPL                  VbK  	  upoV^ ,          PF                   Uu/ uF-  pVPH                  \O        V3R lVPF                   4       4      bK/  	  ppV P7                  VR
\O        4       RR
0/4       V^ ,          PF                   Uu/ uF*  pVPH                  \Q        R VPR                   4       4      bK,  	  ppV P7                  VR
\U        V^R.4      3.R\U        V^R.4      \U        V^R.4      3./4       V^ ,          PF                   Uu/ uF-  pVPH                  \Q        V3R lVPF                   4       4      bK/  	  ppV P7                  VR
. RR
\U        V^R.4      33./4       RRR4       R#   \<         d    T P?                  R4        ELDi ; i  Te   TP3                  4        X	PA                  4        T	PC                  4        T	PE                  \"        R	7       i ; iu upi u upi u upi u upi u upi   + '       g   i     R# ; i)rj   a  ))

            async def deep():
                await asyncio.sleep(0)
                sock.sendall(b"ready"); time.sleep(10_000)  # same line number

            async def c1():
                await asyncio.sleep(0)
                await deep()

            async def c2():
                await asyncio.sleep(0)

            async def main():
                await asyncio.gather(c1(), c2())

            asyncio.run(main())
            Nr0   r1   r2   r3   rm   r4   r5   r{   Task-2c              3   ^   <"   T F"  pSVP                   ,          P                   x  K$  	  R # 5ir   rr   rt   s   & r   rx   ITestGetStackTrace.test_async_gather_remote_stack_trace.<locals>.<genexpr>6  )      $#2 w001;;#2rz   c              3      "   T FE  p\         ;QJ d    . R  VP                   4       F  NK  	  5M! R  VP                   4       4      x  KG  	  R# 5i)c              3   8   "   T F  p\        V4      x  K  	  R # 5ir   r~   r   s   & r   rx   STestGetStackTrace.test_async_gather_remote_stack_trace.<locals>.<genexpr>.<genexpr>G       DO5%,,Or   Nr   r   s   & r   rx   r   F  ;      ' 4 EDDOODEEDDOODDD 4r   r   deepr   c              3      <"   T Fb  pSVP                   ,          P                   \        ;QJ d    . R  VP                   4       F  NK  	  5M! R  VP                   4       4      3x  Kd  	  R# 5i)c              3   8   "   T F  p\        V4      x  K  	  R # 5ir   r~   r   s   & r   rx   r   ^  r   r   Nr   r   s   & r   rx   r   [  T      '
 !0 #4>>2<<HHHHH !0r   r{   r   )+r   r:   r;   r   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   r	   rI   r   rJ   rK   rL   rM   rN   rO   rP   r   r*   r&   rQ   rR   rS   rT   rU   r   rs   rX   r   r   r   r   r   rZ   r[   r2   r\   r]   r   r^   r_   r`   ra   rb   rc   r   r   rs   r   r   r   rw   s   &                 @r   $test_async_gather_remote_stack_trace6TestGetStackTrace.test_async_gather_remote_stack_trace  s&     !( )-v .
6 !!Xh=JHHZ "MM&..&:L:LMM$$V%6%68K8KQOT23$$]3  #+J&IK M.$$cnnk%BC#0#7#7#9 ##%(--d3  843AEE: !,!'')}- ,7q>+D+D+D4+D   2	i5 2
 0;1~/H/H/Htd"/HJ (N55'
 6D	  $#'??$ !  6 $ ' 'cexj (N55 
 6D	  ' $ 4 4' !  6     {B&? @BC!;F";<!;D"9:, (N55	+ 6D  '
 !%' !  6 ( 	+ +b!E;F*C$D#FGo "!$ # F
 !,!'')}-'  *	+[ "!!s}   C!Q'B O'AQP>1QQ Q83Q+6Q!0QAQ'3Q(QO,(O/+O,,O//AP;;QQ(	c                	  a \        4       p\        P                  ! R V R24      pRp\        P                  ! 4       ;_uu_ 4       p\
        P                  P                  VR4      p\
        P                  ! V4       \        P                  ! \        P                  \        P                  4      pVP                  \        P                  \        P                  ^4       VP                  RV34       VP!                  \"        4       VP%                  ^4       \'        VRV4      pRp \(        P*                  ! \,        P.                  V.4      p	VP1                  4       w  rVP3                  4        VP5                  R4      pV P7                  VR4       \9        V	P:                  4      pVe   VP3                  4        X	PA                  4        V	PC                  4        V	PE                  \"        R	7       V^ ,          PF                   Uu. uF  qPH                  NK  	  ppR F  pV PK                  W4       K  	  V^ ,          PF                   Uu/ uF  qPL                  VbK  	  upoV^ ,          PF                   Uu/ uF-  pVPH                  \O        V3R lVPF                   4       4      bK/  	  ppV P7                  VR
\O        4       RR
0/4       V^ ,          PF                   Uu/ uF*  pVPH                  \Q        R VPR                   4       4      bK,  	  ppV P7                  VR
\U        \V        PX                  \Z        R.4      \U        V^R.4      3.R\U        V^R.4      \U        V^R.4      \U        \V        PX                  \Z        R.4      3./4       V^ ,          PF                   Uu/ uF-  pVPH                  \Q        V3R lVPF                   4       4      bK/  	  ppV P7                  VR
. RR
\U        \V        PX                  \Z        R.4      \U        V^R.4      33./4       RRR4       R#   \<         d    T P?                  R4        ELi ; i  Te   TP3                  4        X	PA                  4        T	PC                  4        T	PE                  \"        R	7       i ; iu upi u upi u upi u upi u upi   + '       g   i     R# ; i)a              import asyncio.staggered
            import time
            import sys
            import socket
            # Connect to the test process
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect(('localhost', a  ))

            async def deep():
                await asyncio.sleep(0)
                sock.sendall(b"ready"); time.sleep(10_000)  # same line number

            async def c1():
                await asyncio.sleep(0)
                await deep()

            async def c2():
                await asyncio.sleep(10_000)

            async def main():
                await asyncio.staggered.staggered_race(
                    [c1, c2],
                    delay=None,
                )

            asyncio.run(main())
            Nr0   r1   r2   r3   rm   r4   r5   r{   r   c              3   ^   <"   T F"  pSVP                   ,          P                   x  K$  	  R # 5ir   rr   rt   s   & r   rx   QTestGetStackTrace.test_async_staggered_race_remote_stack_trace.<locals>.<genexpr>  r   rz   c              3      "   T FE  p\         ;QJ d    . R  VP                   4       F  NK  	  5M! R  VP                   4       4      x  KG  	  R# 5i)c              3   8   "   T F  p\        V4      x  K  	  R # 5ir   r~   r   s   & r   rx   [TestGetStackTrace.test_async_staggered_race_remote_stack_trace.<locals>.<genexpr>.<genexpr>  r   r   Nr   r   s   & r   rx   r     r   r   staggered_racer   r   r   z$staggered_race.<locals>.run_one_coroc              3      <"   T Fb  pSVP                   ,          P                   \        ;QJ d    . R  VP                   4       F  NK  	  5M! R  VP                   4       4      3x  Kd  	  R# 5i)c              3   8   "   T F  p\        V4      x  K  	  R # 5ir   r~   r   s   & r   rx   r     r   r   Nr   r   s   & r   rx   r     r   r   r   ).r   r:   r;   r   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   r	   rI   r   rJ   rK   rL   rM   rN   rO   rP   r   r*   r&   rQ   rR   rS   rT   rU   r   rs   rX   r   r   r   r   r   r   rW   r   r   s   &                 @r   ,test_async_staggered_race_remote_stack_trace>TestGetStackTrace.test_async_staggered_race_remote_stack_tracen  s     !( )-v .
< !!Xh=JHHZ "MM&..&:L:LMM$$V%6%68K8KQOT23$$]3  #+J&IK M.$$cnnk%BC#0#7#7#9 ##%(--d3  843AEE: !,!'')}- ,7q>+D+D+D4+D   2	i5 2
 0;1~/H/H/Htd"/HJ (N55'
 6D	  $#'??$ !  6 $ ' 'cexj (N55 
 6D	  ' $ 4 4' !  6     !9#5#5s<L"MN!;F";< !;F";<!;D"9:!$-$6$6$'$J!"
D (N55	+ 6D  '
 !%' !  6 ( 	+ +b$ %%.%7%7>N$O!" !&{B&? @	
G "!$ # F
 !,!'')}-'  B	+s "!!s~   C!R4'B P)'AR4R1R4R  R483R%+6R4!0R*BR4%3R/AR4)Q	QQ		QARR44S	c                F   \        4       p\        P                  ! R V R24      pRp\        P                  ! 4       ;_uu_ 4       p\
        P                  P                  VR4      p\
        P                  ! V4       \        P                  ! \        P                  \        P                  4      pVP                  \        P                  \        P                  ^4       VP                  RV34       VP!                  \"        4       VP%                  ^4       \'        VRV4      pRp \(        P*                  ! \,        P.                  V.4      p	VP1                  4       w  rVP3                  4        \5        R4       F0  p
RpVP7                  \9        V4      4      pV P;                  W4       K2  	  \=        \"        4       F  p
 \?        V	P@                  4      p M	  V P;                  \9        X4      ^4       V P;                  \9        V^ ,          4      ^4       V P;                  V^,          ^ . 34       V^ ,          ^,          pV PI                  \9        V4      R4       \K        \L        PN                  \P        R.4      \K        \L        PN                  \P        R.4      \K        V^<R.4      .pV PS                  \U        \P        R\W        V\P        .4      .. .4      V4       V PS                  \U        \P        R\W        \K        \X        PN                  \P        R.4      .\P        .4      .\W        \K        \L        PN                  \P        R.4      \K        \L        PN                  \P        R.4      \K        V\P        R.4      .\P        .4      ..4      V4       V PS                  \U        \P        R\W        \K        \Z        PN                  \P        R.4      \K        V^&R.4      .\P        .4      .\W        \K        \L        PN                  \P        R.4      \K        \L        PN                  \P        R.4      \K        V^)R.4      .\P        .4      ..4      V4       \W        \K        \L        PN                  \P        R.4      \K        \L        PN                  \P        R.4      \K        V^)R.4      .\P        .4      .pV Uu. uF  pVP\                  V8X  g   K  VNK  	  ppV PI                  \9        V4      R4       \,        P^                  R8w  d5   V P;                  VR,          P\                  VR,          P\                  4       Te   TP3                  4        X	Pe                  4        T	Pg                  4        T	Pi                  \"        R7        RRR4       R#   \B         d   p\E        T4      pTPG                  R4      '       d    Rp?EK  TPG                  R	4      '       d    Rp?EK  TPG                  R
4      '       d    Rp?EK5  TPG                  R4      '       d    Rp?EKS  h Rp?ii ; iu upi   \`         d    T Pc                  R4        ELi ; i  Te   TP3                  4        X	Pe                  4        T	Pg                  4        T	Pi                  \"        R7       i ; i  + '       g   i     R# ; i)a              import asyncio
            import os
            import random
            import sys
            import socket
            from string import ascii_lowercase, digits
            from test.support import socket_helper, SHORT_TIMEOUT

            HOST = '127.0.0.1'
            PORT = socket_helper.find_unused_port()
            connections = 0

            # Connect to the test process
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect(('localhost', a  ))

            class EchoServerProtocol(asyncio.Protocol):
                def connection_made(self, transport):
                    global connections
                    connections += 1
                    self.transport = transport

                def data_received(self, data):
                    self.transport.write(data)
                    self.transport.close()

            async def echo_client(message):
                reader, writer = await asyncio.open_connection(HOST, PORT)
                writer.write(message.encode())
                await writer.drain()

                data = await reader.read(100)
                assert message == data.decode()
                writer.close()
                await writer.wait_closed()
                # Signal we are ready to sleep
                sock.sendall(b"ready")
                await asyncio.sleep(SHORT_TIMEOUT)

            async def echo_client_spam(server):
                async with asyncio.TaskGroup() as tg:
                    while connections < 1000:
                        msg = list(ascii_lowercase + digits)
                        random.shuffle(msg)
                        tg.create_task(echo_client("".join(msg)))
                        await asyncio.sleep(0)
                    # at least a 1000 tasks created. Each task will signal
                    # when is ready to avoid the race caused by the fact that
                    # tasks are waited on tg.__exit__ and we cannot signal when
                    # that happens otherwise
                # at this point all client tasks completed without assertion errors
                # let's wrap up the test
                server.close()
                await server.wait_closed()

            async def main():
                loop = asyncio.get_running_loop()
                server = await loop.create_server(EchoServerProtocol, HOST, PORT)
                async with server:
                    async with asyncio.TaskGroup() as tg:
                        tg.create_task(server.serve_forever(), name="server task")
                        tg.create_task(echo_client_spam(server), name="echo client spam")

            asyncio.run(main())
            Nr0   r1   r2   i  rm   zTask list appears corruptedz3Invalid linked list structure reading remote memoryzUnknown error reading memoryzUnhandled frame ownerr   r   r   r{   zserver taskzServer.serve_foreverzTask-4sleepecho_clientecho_client_spamr    r4   r5   )5r   r:   r;   r   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   r	   rI   r   rJ   rK   rL   rM   rN   rO   rangerP   r   r   r
   r,   r&   RuntimeErrorstr
startswithassertGreaterEqualr   r   rW   r   rX   r   r   r   r   r   platformrQ   rR   rS   rT   rU   )rZ   r[   r2   r\   r]   r   r^   r_   r`   ra   rb   expected_responserc   all_awaited_byremsgentries
main_stackexpected_awaited_byr   tasks_with_awaiteds   &                    r   test_async_global_awaited_by.TestGetStackTrace.test_async_global_awaited_by
  s,     !( )-v 2.AC
H !!Xh=JHHZ "MM&..&:L:LMM$$V%6%68K8KQOT23$$]3  #+J&IK MT.$$cnnk%BC#0#7#7#9 ##%tA(0%,11#6G2HIH$$XA % $M2A);AEE)B$ ) 3,   ^!4a8  ^A%6!7;  !2QG<(+A.''Gd; z22C9KLM#,,c3HI {B78
 h:s2C)D(ErJ 	 ) ( -64?4H4H474J12-.)* ),%&!"" !) -64>4G4G474F12-. -64>4G4G474I12-. -61<c60J-.)*& ),)%&!"'-/` c2f $ ( -616g0N-. -64?464A12-.	)* ),%&!"( !) -64>4G4G474F12-. -64>4G4G474I12-. -64?464F12-.)*. ),1%&!"-46n q9x  !*(2(;(;(+(:%&!" !*(2(;(;(+(=%&!" !*%0"6H$I!"&  )'#8 !(& '*== D ' # &
 '',>(?F
 <<7*$$*2.99.. !,!'')}- "!, (  ""g>>*GHH$ ^^Q  % ^^,JKK$ ^^,CDD$b& # F
 !,!'')}- "!!s   C!Z&BX VKX(X XA&X,A
ZX	"X	.X5X	XX	*X1X	XX	X	XX=9Y <X==Y  AZZZ 	c           	        \        \        P                  ! 4       4      pR pV F#  w  r4V\        P                  ! 4       8X  g   K!  Tp M	  V P                  V4       V P                  XR,          \        \        \         P                  P                  ^,           R.4      \        \        V P                  P                  P                  ^,           R.4      .4       R # )N:N   Nr$   z!TestGetStackTrace.test_self_trace)r$   r=   getpidrV   get_native_idassertIsNotNoner   r   rW   __code__co_firstlinenotest_self_trace)rZ   r\   this_tread_stack	thread_idrf   s   &    r   r   !TestGetStackTrace.test_self_trace7  s     &biik2   +II3355#(  !, 	-."I '00??!C)  ,,55DDqH;	
r   z2Free threaded builds don't have an 'active thread'c                   \        4       p\        P                  ! R V R24      p\        P                  ! 4       ;_uu_ 4       p\
        P                  P                  VR4      p\
        P                  ! V4       \        P                  ! \        P                  \        P                  4      pVP                  \        P                  \        P                  ^4       VP                  RV34       VP!                  \"        4       VP%                  ^4       \'        VRV4      pRp \(        P*                  ! \,        P.                  V.4      pVP1                  4       w  ryVP3                  4        Rp
RV
9  d   WP5                  R4      ,          p
K   R	V
9  d   WP5                  R4      ,          p
K   \7        VP8                  R
R7      p\;        ^
4       F{  p	VP=                  4       pRpV F@  w  rV'       g   K  V^ ,          pVP>                  R8X  g   K+  VP@                  ^8  g   K>  R
pKB  	  V'       d    M+\B        PD                  ! R4       K}  	  V PG                  R4       \7        VP8                  R
R7      pVP=                  4       pVe   VP3                  4        XPM                  4        VPO                  4        VPQ                  \"        R7       V PS                  \U        X4      ^R4       V PW                  \U        X4      ^R4       V^ ,          ^ ,          pV Uu. uF  pV^ ,          NK  	  ppV PY                  VVR4       RRR4       R#   \H         d    T PK                  R4        Li ; i  Te   TP3                  4        XPM                  4        TPO                  4        TPQ                  \"        R7       i ; iu upi   + '       g   i     R# ; i)z            import time, sys, socket, threading

            # Connect to the test process
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect(('localhost', a  ))

            def worker_thread(name, barrier, ready_event):
                barrier.wait()  # Synchronize thread start
                ready_event.wait()  # Wait for main thread signal
                # Sleep to keep thread alive
                time.sleep(10_000)

            def main_work():
                # Do busy work to hold the GIL
                sock.sendall(b"working\n")
                count = 0
                while count < 100000000:
                    count += 1
                    if count % 10000000 == 0:
                        pass  # Keep main thread busy
                sock.sendall(b"done\n")

            # Create synchronization primitives
            num_threads = 3
            barrier = threading.Barrier(num_threads + 1)  # +1 for main thread
            ready_event = threading.Event()

            # Start worker threads
            threads = []
            for i in range(num_threads):
                t = threading.Thread(target=worker_thread, args=(f"Worker-{i}", barrier, ready_event))
                t.start()
                threads.append(t)

            # Wait for all threads to be ready
            barrier.wait()

            # Signal ready to parent process
            sock.sendall(b"ready\n")

            # Signal threads to start waiting
            ready_event.set()

            # Now do busy work to hold the GIL
            main_work()
            r0   r1   r2   Nr   rm   r3   s   workingT)r"   F	main_workg?z/Main thread did not start its busy work on time)only_active_threadr4   r5   zShould have multiple threadsz"Should have exactly one GIL holderz&GIL holder should be among all threads)-r   r:   r;   r   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   r	   rI   r   rJ   rK   rL   rM   rN   rO   rP   r   r&   r   r$   funcnamelinenotimer   rY   rQ   rR   rS   rT   rU   assertGreaterr   r   rX   )rZ   r[   r2   r]   r   r^   r_   r`   ra   rb   rc   unwinder_all
all_tracesfoundr   rf   current_frameunwinder_gil
gil_tracesgil_thread_idtraceall_thread_idss   &                     r   test_only_active_thread)TestGetStackTrace.test_only_active_threadZ  s*     !(
 )-v )..0
d !!Xh=JHHZ  #MM&..&:L:LMM$$V%6%68K8KQOT23$$]3  #+J&IK M4.$$cnnk%BC#0#7#7#9 ##% h. 2 24 88H !0 2 24 88H  .aeeFrA!-!=!=!?J!E,6(	$$(-a)22kA - 4 4r 9$(E -7 JJsO# #& III
  .aeeM)99;
 !,!'')}- J$B
 J$H
 'qM!,M4>?J5eAhhJN?MM8a "!p # F
 !,!'')}- @_ "!!s_   C!O$C)MM%M3AMBON?/OM-*M0,M--M00AN<<OO	 )__name__
__module____qualname____firstlineno__maxDiffskip_if_not_supportedunittestskipIfrL   r   r   rg   r   r   r   r   r   r   r   r   __static_attributes____classdictcell__)__classdict__s   @r   r.   r.   A   s/    G__BB(B$B?NI	 
NI` __BB(B$B?q	 
qf __BB(B$B?Q2	 
Q2f __BB(B$B?~	 
~@ __BB(B$B?U	 
Un __BB(B$B?f.	 
f.P	 __BB(B$B?
	 

< __BB(B$B? NOI P	 Ir   r.   __main__),r  r=   r:   r   rL   rA   rV   r   asyncior   r   r   r   unittest.mockr   test.supportr   r	   r
   r   test.support.script_helperr   test.support.socket_helperr   rJ   r   _remote_debuggingr   r   r   r   ImportErrorSkipTestr   r  r   r  r$   r*   r,   TestCaser.   r   r   r   r   r   <module>r     s    	   
    = =   3 7 " <0?? !  	$ 	$LLG#	$ 	$LLG#0 &
,
)
h)) hV% zMMO a&  


< s   C3 3D