� !A?h!��J�dgZddlmZddlmZddlmZGd�d��ZdS)� TaskGroup�)�events)� exceptions)�tasksc�T�eZdZdZd�Zd�Zd�Zd�Zddd�d�Zd e d e fd �Z d �Z d �Z dS)ra9Asynchronous 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|_ dS)NF) �_entered�_exiting� _aborting�_loop� _parent_task�_parent_cancel_requested�set�_tasks�_errors� _base_error�_on_completed_fut��selfs �?/opt/alt/python-internal/lib64/python3.11/asyncio/taskgroups.py�__init__zTaskGroup.__init__sV���� ��� ������ � ���(-��%��e�e�� ��� ����!%�����c�t�dg}|jr*|�dt|j������|jr*|�dt|j������|jr|�d��n|jr|�d��d�|��}d|�d�S) N�ztasks=zerrors=� cancelling�entered� z )r�append�lenrr r �join)r�info�info_strs r�__repr__zTaskGroup.__repr__(s����t�� �;� 5� �K�K�3��T�[�!1�!1�3�3� 4� 4� 4� �<� 7� �K�K�5�#�d�l�"3�"3�5�5� 6� 6� 6� �>� #� �K�K� � %� %� %� %� �]� #� �K�K� � "� "� "��8�8�D�>�>��'�H�'�'�'�'rc���K�|jrtd|�d����|j�tj��|_t j|j��|_|j�td|�d����d|_|S)N� TaskGroup z has already been enteredz! cannot determine the parent taskT)r � RuntimeErrorr r�get_running_loopr� current_taskr rs r� __aenter__zTaskGroup.__aenter__6s����� �=� @��>�T�>�>�>�@�@� @� �:� ��0�2�2�D�J�!�.�t�z�:�:��� � � $��F�T�F�F�F�H�H� H��� �� rc���K�d|_|�#|�|��r|j�||_|tjur|nd}|jr|j���dkrd}|�|js|� ��|j r{|j �|j � ��|_ |j �d{V��n9#tj$r'}|js|}|� ��Yd}~nd}~wwxYwd|_ |j �{|j�|j�|r |js|�|�(|tjur|j�|��|jr% t!d|j��}|d�#d|_wxYwdS)NT�zunhandled errors in a TaskGroup)r �_is_base_errorrr�CancelledErrorrr �uncancelr �_abortrrr � create_futurerr�BaseExceptionGroup)r�et�exc�tb�propagate_cancellation_error�ex�mes r� __aexit__zTaskGroup.__aexit__Ds������� � �O��#�#�C�(�(� �� �(�"�D� ���2�2�2�C�C�� %� � (� 4�� �)�)�+�+�q�0�0�04�,� �>��>� �� � � � � � �k� *��%�-�)-��)A�)A�)C�)C��&� "��,�,�,�,�,�,�,�,�,���,� "� "� "��~� "�46�0��K�K�M�M�M���������� "����&*�D� "�'�k� *�. � � '��"� "� (� /�� � /�.� .� �>�b� �(A�A�A� �L� � �� $� $� $� �<� $� $�'�(I�4�<�X�X���d�"��#�� �#�#�#�#� $� $s$�1 B?�?C5�C0�0C5�E)�) E2N)�name�contextc��|jstd|�d����|jr|jstd|�d����|jrtd|�d����|�|j�|��}n|j�||���}tj||��|� |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 rr r � create_taskr�_set_task_name�add_done_callback� _on_task_done�add)r�coror:r;�tasks rr=zTaskGroup.create_task�s��� �}� K��I�D�I�I�I�J�J� J� �=� B��� B��@�D�@�@�@�A�A� A� �>� G��E�D�E�E�E�F�F� F� �?��:�)�)�$�/�/�D�D��:�)�)�$��)�@�@�D� ��T�4�(�(�(� ���t�1�2�2�2� � �������� rr4�returnc�:�t|ttf��S)N)� isinstance� SystemExit�KeyboardInterrupt)rr4s rr-zTaskGroup._is_base_error�s���#� �,=�>�?�?�?rc�x�d|_|jD]*}|���s|����+dS)NT)r r�done�cancel)r�ts rr0zTaskGroup._abort�sB������� � �A��6�6�8�8� ���� � � �� � rc��|j�|��|j�:|js3|j���s|j�d��|���rdS|���}|�dS|j�|��|� |��r|j �||_ |j ���r,|j � d|�d|j �d�||d���dS|js=|js8|���d|_|j ���dSdSdS)NTzTask z% has errored out but its parent task z is already completed)�message� exceptionrC)r�discardrrJ� set_result� cancelledrOrrr-rr r �call_exception_handlerr rr0rK)rrCr4s rr@zTaskGroup._on_task_done�s��� � ���D�!�!�!� � !� -�d�k� -��)�.�.�0�0� 8��&�1�1�$�7�7�7� �>�>� � � � �F��n�n���� �;� �F� � ���C� � � � � � �s� #� #� #��(8�(@�"�D� � � � !� !� #� #� � �J� -� -�L�4�L�L�#'�#4�L�L�L� �� /�/� � � � �F��~� '�d�&C� '�& �K�K�M�M�M�,0�D� )� � � $� $� &� &� &� &� &�+ '� '� '� 'r)�__name__� __module__� __qualname__�__doc__rr$r*r9r=� BaseException�boolr-r0r@�rrrr s��������� &� &� &� (� (� (� � � �O$�O$�O$�b)-�d������0@�-�@�D�@�@�@�@����2'�2'�2'�2'�2'rN)�__all__rrrrrrZrr�r\s��� �-��������������������^'�^'�^'�^'�^'�^'�^'�^'�^'�^'r