+
     Bi&                         R t ^ RIHtHt ^ RIHt ^ RIHt ^ RIt^ RI	H
t
Ht  ! R R]4      t ! R R	]4      tR
 R ltR tR tR tR tR tR tRR ltR tR R ltR tR R ltR R ltR R ltR# )z3Tools to analyze tasks running in asyncio programs.)defaultdict
namedtuple)count)EnumN)RemoteUnwinder	FrameInfoc                       ] tR t^	t^t^tRtR# )NodeType N)__name__
__module____qualname____firstlineno__	COROUTINETASK__static_attributes__r
       $/usr/lib/python3.14/asyncio/tools.pyr	   r	   	   s    IDr   r	   c                   B   a a ] tR t^t oRtV3R lV 3R lltRtVtV ;t# )CycleFoundExceptionz8Raised when there is a cycle when drawing the call tree.c                `   < V ^8  d   QhRS[ S[ S[,          ,          RS[S[S[3,          RR/# )   cyclesid2namereturnN)listintdictstr)format__classdict__s   "r   __annotate__ CycleFoundException.__annotate__   s9      cO #s(^ 	r   c                >   < \         SV `  W4       Wn        W n        R # N)super__init__r   r   )selfr   r   	__class__s   &&&r   r&   CycleFoundException.__init__   s    
 	)r   )r   r   )	r   r   r   r   __doc__r&   r   __classdictcell____classcell__)r(   r    s   @@r   r   r      s     B  r   r   c                F    V ^8  d   QhR\         \        ,          R\         /# )r   elemr   )r   r   )r   s   "r   r!   r!      s      c)m  r   c                     \        V \        4      '       gX   V P                  ^ 8X  d   V P                  R8X  d   V P                   # V P                   RV P                   RV P                   2# V # )      :)
isinstancer   linenofilenamefuncname)r.   s   &r   _format_stack_entryr8      sZ    dC  ;;! 3mm_%mm_Admm_Adkk]CCKr   c           	         / . / r2pV  F  pVP                    F  pVP                  pVP                  pWqV&   VP                  '       d>   VP                   F-  pVP                  p	V	 U
u. uF  p
\        V
4      NK  	  pp
WV&   K/  	  VP                   '       g   K  VP                    FH  pVP                  p	VP                  pV	 U
u. uF  p
\        V
4      NK  	  pp
VP                  WV34       KJ  	  K  	  K  	  WV3# u up
i u up
i r$   )
awaited_bytask_id	task_namecoroutine_stack
call_stackr8   append)resultr   awaitstask_stacksawaited_info	task_infor;   r<   	coro_infor>   frameinternal_stackparent_task_idstacks   &             r   _indexrJ   %   s   #%r2[G%00I''G!++I(G (((!*!:!:I!*!5!5JNX%YjU&9%&@jN%Y+9( "; ###!*!5!5I!*!5!5J%.%8%8NEOPZE07ZEPMM>'"BC	 "6 1 ( K'' &Z Qs   'C=
D
c                   aaaa V P                  4        UUu/ uF  w  r4\        P                  V3VbK  	  uppo\        \        4      o\        \
        4      o\        ^4      oVVVV3R lpV Fl  w  rgp\        P                  V3p	\        V4       F  p
V! W4      p	K  	  \        P                  V3pVSV	,          9  g   KT  SV	,          P                  V4       Kn  	  V UUu0 uF  w  p qkK
  	  pppV  FE  pW9  g   K  W9   g   K  \        P                  V3p	\        W.,          4       F  p
V! W4      p	K  	  KG  	  SS3# u uppi u uppi )   c                   < VSV ,          9   d   SV ,          V,          # \         P                  R\        S4       23pVSV&   SV ,          P                  V4       VSV ,          V&   V# )z:Get existing coroutine node or create new one under parentc)r	   r   nextr?   )parentrF   node_keychildren	cor_nodesid2labelnext_cor_ids   && r   get_or_create_cor_node+_build_tree.<locals>.get_or_create_cor_nodeD   sn    If%%V$U++&&!D,=+>(?@")#+	&% r   )	itemsr	   r   r   r   r   r   reversedr?   )r   rA   rB   tidnamerV   	parent_idrI   child_idcurrF   	child_key_awaiting_tasksr;   rR   rS   rT   rU   s   &&&            @@@@r   _build_treerb   >   s-   <CMMOLOys$d*OLH4 HD!I(K	 	 '-"	(}}i(e_E(4C % ]]H-	HSM)SM  + '- 8>>vOIq!ivN>(W-C=='*C!+"67,S8 8  XE M6 ?s   E#E	c                     VP                  4        UUu0 uF  q" F  q3kK  	  K  	  pppV  Uu. uF  qUV9  g   K  VNK  	  up# u uppi u upi r$   )values)rT   rR   kidsrN   all_childrenns   &&    r   _rootsrh   d   sL    "*//"3B"3$TATA"3LB9x!L#8AAx99 C9s   AA	A	c                j    \        \        4      pV  F  w  r#pW,          P                  V4       K  	  V# )u3   Return {parent_task_id: {child_task_id, …}, …}.)r   setadd)rA   gr\   _stackr]   s   &    r   _task_graphrn   i   s0    CA'-#	8	" (.Hr   c                   a aaaaaaa ^ ^^uooo\        V3R l4      o. . uooVVVVVVV V3R lo\        S 4       F  pSV,          S8X  g   K  S! V4       K  	  S# )z
Depth-first search for back-edges.

Returns a list of cycles (each cycle is a list of task-ids) or an
empty list if the graph is acyclic.
c                     < S # r$   r
   )WHITEs   r   <lambda>_find_cycles.<locals>.<lambda>y   s    r   c                 :  < SSV &   S
P                  V 4       S	P                  V R4       FX  pSV,          S8X  d   S! V4       K  SV,          S8X  g   K+  S
P                  V4      pSP                  S
VR  V.,           4       KZ  	  SSV &   S
P                  4        R # )Nr
   )r?   getindexpop)vwiBLACKGREYrq   colorr   dfsgraphpaths   &  r   r~   _find_cycles.<locals>.dfs|   s    aA1b!AQx5 AqT!JJqMd12h!n- " a
r   )r   r   )	r   rx   r{   r|   rq   r}   r   r~   r   s	   f @@@@@@@r   _find_cyclesr   q   s^     AqE4&ErLD&
 
 %[8uF  Mr   c                 8    \        V 4      pVP                  4       # r$   )r   get_all_awaited_by)pidunwinders   & r   r   r      s    c"H&&((r   c                  aaa	a
aa \        V 4      w  r4p\        V4      p\        V4      pV'       d   \        Ws4      h\	        W4V4      w  o
o	VV
V3R loRV	VV3R llo\        S
S	4       Uu. uF  pS! V4      NK  	  up# u upi )z
Build a list of strings for pretty-print an async call tree.

The call tree is produced by `get_all_async_stacks()`, prefixing tasks
with `task_emoji` and coroutine frames with `cor_emoji`.
c                 `   < V ^ ,          \         P                  8X  d   SMSpV RSV ,           2# )r0   r2   )r	   r   )nodeflag	cor_emojilabels
task_emojis   & r   pretty build_async_tree.<locals>.pretty   s.    !!W5z9q''r   c           	        < Vf   . pTP                  T V'       d   RMR S	! V 4       24       Y'       d   RMR,           pSP                  V . 4      p\        V4       F"  w  rgS
! WtV\        V4      ^,
          8H  V4       K$  	  V# )Nu
   └── u
   ├── z    u   │   )r?   ru   	enumeratelen)r   prefixlastbufnew_prefre   rz   kidrR   r   renders   &&&&    r   r    build_async_tree.<locals>.render   s{    ;C

fXdlEfTl^TUtV:||D"%oFA3!s4y1}"4c: &
r   )r1   TN)rJ   rn   r   r   rb   rh   )r@   r   r   r   rA   rB   rl   r   rootrR   r   r   r   s   &ff      @@@@r   build_async_treer      s{     $*&> G[FA!_F!&22"7K@FH(  &,FH%=>%=TF4L%=>>>s   -Bc                 N   \        V 4      w  p p. pV  EF  pVP                  pVP                   EF`  pVP                  pVP                  pVP
                   U	U
u. uF  p	V	P                   F  p
V
NK  	  K  	  pp	p
R P                  R V 4       4      pVP                  '       g#   VP                  V\        V4      WRRR.4       K  VP                   F  pVP                  pVP                   Uu. uF$  p\        V4      P                  R4      ^ ,          NK&  	  ppR P                  V4      pVP                  VR4      p\        V\        4      '       d   \        V4      M
\        V4      pVP                  V\        V4      WVVV.4       K  	  EKc  	  EK  	  V# u up
p	i u upi )z -> c              3   d   "   T F&  p\        V4      P                  R 4      ^ ,          x  K(  	  R# 5i)r2   N)r8   split).0xs   & r   	<genexpr>#build_task_table.<locals>.<genexpr>   s/      %4,2q &9%;%A%A#%Fq%I%I,2s   .0r1   0x0r2   Unknown)rJ   	thread_idr:   r;   r<   r=   r>   joinr?   hexr8   r   ru   r4   r   r   )r@   r   r`   tablerC   r   rD   r;   r<   cororF   frames
coro_stackrE   r\   r   awaiter_framesawaiter_chainawaiter_nameparent_id_strs   &                   r   build_task_tabler      s   6NMGQE **	%00I''G!++I )2(A(A 3(A"&// "1 (AF 3 %4,2%4 4J '''iWyE+ , '11	%//	)2)=)="?)=A #6a"8">">s"CA"F"F)=  "? &N ;&{{9i@3=i3M3MY$'	N  iWy)<H I 2% 1 @ L13"?s   F
1*F"
c                $    V ^8  d   QhR\         /# )r   	exception)r   )r   s   "r   r!   r!      s     3 3&9 3r   c                   a  \        R \        P                  R7       \        R\        P                  R7       S P                   F<  pRP	                  V 3R lV 4       4      p\        RV 2\        P                  R7       K>  	  R# )z9ERROR: await-graph contains cycles - cannot print a tree!)filer1   u    → c              3   n   <"   T F*  pSP                   P                  V\        V4      4      x  K,  	  R # 5ir$   )r   ru   r   )r   rZ   r   s   & r   r   )_print_cycle_exception.<locals>.<genexpr>   s+     Pasi//33CSBBas   25zcycle: N)printsysstderrr   r   )r   rN   inamess   f  r   _print_cycle_exceptionr      sY    	
ECJJW	"3::PaPPx szz2 r   c                 H    \        R4       \        P                  ! ^4       R# )z
Prints a message pointing to platform-specific permission help text and exits the program.
This function is called when a PermissionError is encountered while trying
to attach to a process.
zError: The specified process cannot be attached to due to insufficient permissions.
See the Python documentation for details on required privileges and troubleshooting:
https://docs.python.org/3.14/howto/remote_debugging.html#permission-requirements
N)r   r   exitr
   r   r   exit_with_permission_help_textr      s     
	]
 HHQKr   c                0    V ^8  d   QhR\         R\        /# )r   r   r   )r   r   )r   s   "r   r!   r!      s     	) 	)s 	)t 	)r   c                     \        V 4      #   \         dL   pTP                  e   TP                  pK  \        RT 24       \        P
                  ! ^4        R p?R # R p?i\         d   p\        4         R p?R # R p?ii ; i)NzError retrieving tasks: )r   RuntimeError__context__r   r   r   PermissionErrorr   )r   es   & r   _get_awaited_by_tasksr      sd    )!#&& mm'A(,- )&(()s'   
 BA AB+B,
A<<Bc                (    V ^8  d   QhR\         RR/# r   r   r   Nr   )r   s   "r   r!   r!      s     m m m mr   c                T   \        V 4      p\        V4      p\        RR RRR RRR RRR RR	R RR
R RRR 24       \        R4       V FZ  p\        V^ ,          R RV^,          R RV^,          R RV^,          R RV^,          R RV^,          R RV^,          R 24       K\  	  R# )z9Build and print a table of all pending tasks under `pid`.rZ   z<10r2   ztask idz<20z	task namezcoroutine stackz<50zawaiter chainzawaiter namez<15z
awaiter idNz------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------)r   r   r   )r   tasksr   rows   &   r   display_awaited_by_tasks_tabler      s     "#&EU#E	+QyoQ{3&7q9J38OqQ`adPeefguvyfzz{  }I  JM  |N  	O 
)QAc!fS\3q6#,aAs|1SVCLPQRUVWRXY\Q]]^_bcd_efi^jkl r   c                (    V ^8  d   QhR\         RR/# r   r   )r   s   "r   r!   r!   	  s      s t r   c                    \        V 4      p \        V4      pX F  p\        RP                  V4      4       K  	  R#   \         d,   p\        T4       \        P
                  ! ^4        Rp?LVRp?ii ; i)z8Build and print a tree of all pending tasks under `pid`.N
)r   r   r   r   r   r   r   r   )r   r   r@   r   trees   &    r   display_awaited_by_tasks_treer   	  s`     "#&E!%(
 diio 	  q!s   = A3!A..A3)z(T)r1   )r*   collectionsr   r   	itertoolsr   enumr   r   _remote_debuggingr   r   r	   	Exceptionr   r8   rJ   rb   rh   rn   r   r   r   r   r   r   r   r   r   r
   r   r   <module>r      sx    9 /   
 7t 
	) 	(2#L:
<)
?>$L3	)mr   