
    d!                     J    d gZ ddlmZ ddlmZ ddlmZ  G d d           ZdS )	TaskGroup   )events)
exceptions)tasksc                   T    e Zd ZdZd Zd Zd Zd ZddddZd	e	d
e
fdZd Zd ZdS )r   a9  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                     d| _         d| _        d| _        d | _        d | _        d| _        t                      | _        g | _        d | _	        d | _
        d S )NF)_entered_exiting	_aborting_loop_parent_task_parent_cancel_requestedset_tasks_errors_base_error_on_completed_futselfs    $  /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/asyncio/taskgroups.py__init__zTaskGroup.__init__   sV    
 (-%ee!%    c                 t   dg}| j         r*|                    dt          | j                               | j        r*|                    dt          | j                              | j        r|                    d           n| j        r|                    d           d                    |          }d| dS )	N ztasks=zerrors=
cancellingentered z
<TaskGroup>)r   appendlenr   r   r	   join)r   infoinfo_strs      r   __repr__zTaskGroup.__repr__(   s    t; 	5KK3T[!1!133444< 	7KK5#dl"3"355666> 	#KK%%%%] 	#KK	"""88D>>'H''''r   c                    K   | j         rt          d| d          d| _         | j        t          j                    | _        t          j        | j                  | _        | j        t          d| d          | S )N
TaskGroup z has been already enteredTz! cannot determine the parent task)r	   RuntimeErrorr   r   get_running_loopr   current_taskr   r   s    r   
__aenter__zTaskGroup.__aenter__6   s      = 	@>T>>>@ @ @:022DJ!.tz::$FTFFFH H H r   c                    K   d| _         |#|                     |          r| j        || _        |t          j        u r|nd }| j        r| j                                        dk    rd }|| j        s| 	                                 | j
        r{| j        | j                                        | _        	 | j         d {V  n9# t          j        $ r'}| j        s|}| 	                                 Y d }~nd }~ww xY wd | _        | j
        {| j
        rJ | j        | j        |r	| j        s||(|t          j        ur| j                            |           | j        r%	 t!          d| j                  }|d # d | _        w xY wd S )NT    zunhandled errors in a TaskGroup)r
   _is_base_errorr   r   CancelledErrorr   r   uncancelr   _abortr   r   r   create_futurer   r   BaseExceptionGroup)r   etexctbpropagate_cancellation_errorexmes          r   	__aexit__zTaskGroup.__aexit__F   s     O##C((  ("D 222CC 	%( 	4 ))++q00 04,>>   k 	*%-)-)A)A)C)C&",,,,,,,,,, " " "~ 
" 460KKMMM" &*D"' k 	** ;'"" ( 	/ 	/..>b
(AAAL$$$< 	$$'(I4<XXd"#####	$ 	$s$   1B? ?C5C00C5E2 2	E;N)namecontextc                   | j         st          d| d          | j        r| j        st          d| d          | j        rt          d| d          || j                            |          }n| j                            ||          }t          j        ||           |	                    | j
                   | j                            |           |S )zbCreate a new task in this group and return it.

        Similar to `asyncio.create_task`.
        r&   z has not been enteredz is finishedz is shutting downN)r;   )r	   r'   r
   r   r   r   create_taskr   _set_task_nameadd_done_callback_on_task_doneadd)r   coror:   r;   tasks        r   r=   zTaskGroup.create_task   s    
 } 	KIDIIIJJJ= 	B 	B@D@@@AAA> 	GEDEEEFFF?:))$//DD:))$)@@DT4(((t1222r   r4   returnc                 h    t          |t                    sJ t          |t          t          f          S )N)
isinstanceBaseException
SystemExitKeyboardInterrupt)r   r4   s     r   r-   zTaskGroup._is_base_error   s.    #}-----#
,=>???r   c                 x    d| _         | j        D ]*}|                                s|                                 +d S )NT)r   r   donecancel)r   ts     r   r0   zTaskGroup._abort   sB     	 	A6688 


	 	r   c                    | j                             |           | j        :| j         s3| j                                        s| j                            d           |                                rd S |                                }|d S | j                            |           | 	                    |          r| j
        || _
        | j                                        r,| j                            d|d| j         d||d           d S | j        s=| j        s8|                                  d| _        | j                                         d S d S d S )NTzTask z% has errored out but its parent task z is already completed)message	exceptionrC   )r   discardr   rK   
set_result	cancelledrP   r   r   r-   r   r   r   call_exception_handlerr   r   r0   rL   )r   rC   r4   s      r   r@   zTaskGroup._on_task_done   s   D!!!!-dk-)..00 8&11$777>> 	Fnn;FC   s## 	#(8(@"D!!## 		 J--L4 L L#'#4L L L 	/ /    F~ 	'd&C 	'& KKMMM,0D)$$&&&&&+	' 	' 	' 	'r   )__name__
__module____qualname____doc__r   r$   r*   r9   r=   rG   boolr-   r0   r@    r   r   r   r      s         
& 
& 
&( ( (   O$ O$ O$b )-d     0@- @D @ @ @ @  2' 2' 2' 2' 2'r   N)__all__r   r   r   r   r   rZ   r   r   <module>r\      s   
 -                  `' `' `' `' `' `' `' `' `' `'r   