
    F\hA'                     @    S r SSKJr  SSKJr  SSKJr   " S S5      rg))	TaskGroup   )events)
exceptions)tasksc                   d    \ rS rSrSrS rS rS rS rS r	SSS	.S
 jr
S\S\4S jrS rS rSrg)r      a  Asynchronous context manager for managing groups of tasks.

Example use:

    async with asyncio.TaskGroup() as group:
        task1 = group.create_task(some_coroutine(...))
        task2 = group.create_task(other_coroutine(...))
    print("Both tasks have completed now.")

All tasks are awaited when the context manager exits.

Any exceptions other than `asyncio.CancelledError` raised within
a task will cancel all remaining tasks and wait for them to exit.
The exceptions are then combined and raised as an `ExceptionGroup`.
c                     SU l         SU l        SU l        S U l        S U l        SU l        [        5       U l        / U l        S U l	        S U l
        g )NF)_entered_exiting	_aborting_loop_parent_task_parent_cancel_requestedset_tasks_errors_base_error_on_completed_futselfs    )/usr/lib/python3.13/asyncio/taskgroups.py__init__TaskGroup.__init__   sN    
 (-%e!%    c                    S/nU R                   (       a'  UR                  S[        U R                   5       35        U R                  (       a'  UR                  S[        U R                  5       35        U R                  (       a  UR                  S5        O"U R
                  (       a  UR                  S5        SR                  U5      nSU S3$ )	N ztasks=zerrors=
cancellingentered z
<TaskGroup>)r   appendlenr   r   r
   join)r   infoinfo_strs      r   __repr__TaskGroup.__repr__(   s    t;;KK&T[[!1 234<<KK'#dll"3!456>>KK%]]KK	"88D>H:Q''r   c                 0  #    U R                   (       a  [        SU < S35      eU R                  c  [        R                  " 5       U l        [
        R                  " U R                  5      U l        U R                  c  [        SU < S35      eSU l         U $ 7f)N
TaskGroup z has already been enteredz! cannot determine the parent taskT)r
   RuntimeErrorr   r   get_running_loopr   current_taskr   r   s    r   
__aenter__TaskGroup.__aenter__6   s     ==TH$=>@ @::002DJ!..tzz:$TH$EFH Hs   BBc                    #    S n U R                  X5      I S h  vN S U l        S U l        S U l        S n$  N! S U l        S U l        S U l        S nf = f7fN)_aexitr   r   r   )r   etexctbs       r   	__aexit__TaskGroup.__aexit__D   s`     
	R-- !%DDL#DC . !%DDL#DCs%   A8 68 A8 AAc                 
  #    SU l         Ub)  U R                  U5      (       a  U R                  c  X l        Ub"  [        U[        R
                  5      (       a  UnOS nUb!  U R                  (       d  U R                  5         U R                  (       a[  U R                  c  U R                  R                  5       U l	         U R                  I S h  vN   S U l	        U R                  (       a  M[  U R                  (       a   eU R                  b   U R                  eU R                  (       a   U R                  R                  5       S:X  a  S n Ub  U R                  (       d   UeS nUb:  [        U[        R
                  5      (       d  U R                  R!                  U5        U R                  (       ak  U R                  R#                  5       (       a4  U R                  R                  5         U R                  R%                  5          ['        SU R                  5      S eg  GNQ! [        R
                   a.  nU R                  (       d  UnU R                  5          S nAGNS nAff = f! S nf = f! S nf = f! S nf = f! S nf = f7f)NT    zunhandled errors in a TaskGroup)r   _is_base_errorr   
issubclassr   CancelledErrorr   _abortr   r   r   create_futurer   r   uncancelr   r!   r   cancelBaseExceptionGroup)r   r2   r3   propagate_cancellation_errorexs        r   r1   TaskGroup._aexitR   s    O##C((  (">jZ-F-FGG+.(+/(>>>  kk%%-)-)A)A)C&",,,, &*D"' kkk* ;;'&&& ((  ))+q0 04,	0+766 ,0(>*R1J1J"K"KLL$<<   ++--!!**,!!((*(5LL  [ -,, "~~ 460KKM"*   C+/($ s   B<J?H" HH" J- JI' 1JI5 !I. #B#JI< JH" "I$6#IJI$$J'I++J.I22I5 5I99J<J  JNnamecontextc                8   U R                   (       d   UR                  5         [        SU < S35      eU R                  (       a1  U R                  (       d   UR                  5         [        SU < S35      eU R
                  (       a   UR                  5         [        SU < S35      eUc  U R                  R                  XS9nOU R                  R                  XUS9nU R                  R                  U5        UR                  U R                  5         UA$ ! Af = f)zRCreate a new task in this group and return it.

Similar to `asyncio.create_task`.
r)   z has not been enteredz is finishedz is shutting down)rE   rD   )r
   closer*   r   r   r   r   create_taskaddadd_done_callback_on_task_done)r   cororE   rF   tasks        r   rI   TaskGroup.create_task   s    
 }}JJLD83HIJJ==JJLD8<@AA>>JJLD83DEFF?::))$):D::))$7)KD 	t112	 s   D Dr3   returnc                 \    [        U[        5      (       d   e[        U[        [        45      $ r0   )
isinstanceBaseException
SystemExitKeyboardInterrupt)r   r3   s     r   r9   TaskGroup._is_base_error   s(    #}----#
,=>??r   c                     SU l         U R                   H*  nUR                  5       (       a  M  UR                  5         M,     g )NT)r   r   doner?   )r   ts     r   r<   TaskGroup._abort   s+    A6688
 r   c                    U R                   R                  U5        U R                  bK  U R                   (       d:  U R                  R                  5       (       d  U R                  R	                  S5        UR                  5       (       a  g UR                  5       nUc  g U R                  R                  U5        U R                  U5      (       a  U R                  c  X l
        U R                  R                  5       (       a2  U R                  R                  SU< SU R                   S3UUS.5        g U R                  (       dD  U R                  (       d2  U R!                  5         SU l        U R                  R#                  5         g g g )NTzTask z% has errored out but its parent task z is already completed)message	exceptionrN   )r   discardr   rX   
set_result	cancelledr]   r   r!   r9   r   r   r   call_exception_handlerr   r   r<   r?   )r   rN   r3   s      r   rL   TaskGroup._on_task_done   s=   D!!!-dkk))..00&&11$7>>nn;C s##(8(8(@"!!## JJ--"4( +##'#4#4"55JL 	/  ~~d&C&C& KKM,0D)$$&+ 'D~r   )
r   r   r
   r   r   r   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r&   r-   r5   r1   rI   rS   boolr9   r<   rL   __static_attributes__ r   r   r   r      sO    
&(`F )-d H@- @D @2'r   r   N)__all__r   r   r   r   r   rj   r   r   <module>rl      s!   
    J' J'r   