%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3.12/test/libregrtest/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3.12/test/libregrtest/__pycache__/run_workers.cpython-312.pyc

�

���f\W��^�ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZmZmZddlmZddlmZmZddlmZddlmZmZddlmZdd	lmZmZm Z m!Z!dd
l"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ddl,m-Z-m.Z.erddl/Z/ddl0Z0d
Z1e1e#k\sJ�dZ2e2e1k\sJ�d
Z3dZ4Gd�d�Z5ejldd��Gd�d��Z7e8Z9e:ede7fe:ede9fzZ;Gd�de<�Z=Gd�de<�Z>Gd�de
j~�Z@deAe@de8dzfd�ZBGd �d!�ZCy)"�N)�Any�Literal�TextIO)�support)�	os_helper�
MS_WINDOWS�)�Logger)�
TestResult�State)�TestResults)�RunTests�WorkerRunTests�JsonFile�JsonFileType)�PROGRESS_MIN_TIME)�StrPath�TestName�format_duration�
print_warning�count�plural�get_signal_name)�create_worker_process�USE_PROCESS_GROUPg>@g�r@gN@c�(�eZdZdZd�Zd�Zd�Zd�Zy)�MultiprocessIteratorz8A thread-safe iterator over tests for multiprocess mode.c�D�tj�|_||_y�N)�	threading�Lock�lock�
tests_iter)�selfr#s  �3/usr/lib/python3.12/test/libregrtest/run_workers.py�__init__zMultiprocessIterator.__init__8s���N�N�$��	�$���c��|Sr��r$s r%�__iter__zMultiprocessIterator.__iter__<s���r'c��|j5|j�t�t|j�cddd�S#1swYyxYwr)r"r#�
StopIteration�nextr*s r%�__next__zMultiprocessIterator.__next__?s:��
�Y�Y�	)����&�#�#�����(�	)�	)�	)�s	�'>�Ac�T�|j5d|_ddd�y#1swYyxYwr)r"r#r*s r%�stopzMultiprocessIterator.stopEs%��
�Y�Y�	#�"�D�O�	#�	#�	#�s��'N)�__name__�
__module__�__qualname__�__doc__r&r+r/r1r)r'r%rr4s��B�%��)�#r'rT)�slots�frozenc�@�eZdZUeed<dZedzed<dZedzed<y)�MultiprocessResult�resultN�
worker_stdout�err_msg)r2r3r4r�__annotations__r;�strr<r)r'r%r9r9Js$���� $�M�3��:�$��G�S�4�Z�r'r9Fc��eZdZy)�
ExitThreadN)r2r3r4r)r'r%r@r@Vs��r'r@c�<��eZdZdededzdedzdef�fd�Z�xZS)�WorkerError�	test_namer<N�stdout�statec�`��t||��}t|||�|_t�|��y)N�rE)rr9�	mp_result�superr&)r$rCr<rDrEr:�	__class__s      �r%r&zWorkerError.__init__[s,���
�I�U�3��+�F�F�G�D���
���r')r2r3r4rr>r&�
__classcell__�rJs@r%rBrBZs9����$����*���t����	�r'rBc
�n��eZdZdeddddf�fd�Zdefd�Zd!d�Zd!d	�Z	d"d
e	dede
dzdedzfd
�Zdejdefd�Zdejdeeedzffd�Zdedede	fd�Zde	dedeedzee
ffd�Zdedefd�Zdededzdedeeeffd�Zdedefd�Zd!d�Zd!d�Zdeddfd �Z�xZ S)#�WorkerThread�	worker_id�runner�
RunWorkers�returnNc� ��t�|��||_|j|_|j|_|j
|_|j|_|j|_d|_	d|_
d|_d|_d|_
y)NF)rIr&rO�runtests�pending�output�worker_timeout�timeout�logrC�
start_time�_popen�_killed�_stopped)r$rOrPrJs   �r%r&zWorkerThread.__init__fsq���
����"�������
��~�~����m�m����,�,����:�:���*.���(,���48��������
r'c��d|j��g}|j�r|jd�n|jd�|j}|r|jd|���|j}|�Wtj�|jz
}|jd|jj��dt|���f�ddj|�zS)	NzWorkerThread #�running�stoppedztest=zpid=ztime=z<%s>� )rO�is_alive�appendrCr[�time�	monotonicrZ�extend�pidr�join)r$�info�test�popen�dts     r%�__repr__zWorkerThread.__repr__ts��� ���� 0�1�2���=�=�?��K�K�	�"��K�K�	�"��~�~����K�K�%��v��'����������!�D�O�O�3�B��K�K�4������0�1� ���!4� 5�6�8�
9�������&�&r'c��|j}|�y|jryd|_tr|�d�}n|�d�}td|��tj
d��	tr/t
j|jtj�y|j�y#t$rYyt$r}td|�d|���Yd}~yd}~wwxYw)NTz process groupz processzKill )�file�flushzFailed to kill z: )r[r\r�print�sys�stderr�os�killpgrg�signal�SIGKILL�kill�ProcessLookupError�OSErrorr)r$rk�what�excs    r%�_killzWorkerThread._kill�s��������=���<�<�������V�>�*�D��V�8�$�D�
��d�V�n�3�:�:�T�:�	=� ��	�	�%�)�)�V�^�^�4��
�
���!�	�
��	=��O�D�6��C�7�;�<�<��	=�s$�4B�
B�	C	�&C	�.C�C	c�2�d|_|j�y)NT)r]r}r*s r%r1zWorkerThread.stop�s����
��
�
�r'rT�	output_fd�tmp_dirc�:�t|||�}||_d|_	|jr|j	�t
�	|j
|j��}|�J�||j�d|_S#tj$r'|jrt
�|j	�d}Ynt$r|jrt
��wxYwn#|j	��xYw	|j�d|_y#|j�d|_wxYw)NF�rX)rr[r\r]r}r@�waitrX�_wait_completed�
subprocess�TimeoutExpiredrz)r$rTrr�rk�retcodes      r%�_run_processzWorkerThread._run_process�s��%�h�	�7�C��������&	��}�}��
�
�� � �
��*�*�T�\�\�*�:���*�*�*��2
� � �"��D�K��3�,�,�

��=�=�%�$��
�
�����
��=�=�%�$��
��	��	��J�J�L����
� � �"��D�K��
� � �"��D�K�s;�"C�!A9�97C�0C�2C�C�D�C%�%D�D�stackc���trtj�}ntjj
}t
jd|d��}|j|�|S)z/Create stdout temporary file (file descriptor).�w+�backslashreplace)�encoding�errors)	r�locale�getencodingrrrDr��tempfile�
TemporaryFile�
enter_context)r$r�r��stdout_files    r%�
create_stdoutzWorkerThread.create_stdout�sW����)�)�+�H��z�z�*�*�H��,�,�T�6>�4F�H��	���K�(��r'c��|jj�}|r tdtj�}d}||fStjdd��}|j|�|j�}tr3tj|�}t|tj�}||fSt|tj�}||fS)zCreate JSON file.Nr��utf8�r�)rT�json_file_use_stdoutrr�STDOUTr�r�r��filenor�msvcrt�
get_osfhandle�WINDOWS_HANDLE�UNIX_FD)r$r�r��	json_file�json_tmpfile�json_fd�json_handles       r%�create_json_filezWorkerThread.create_json_file�s��� $�}�}�A�A�C��� ��|�':�':�;�I��L��<�(�(�$�1�1�$��H�L�����-�"�)�)�+�G��$*�#7�#7��#@��$�[�%1�%@�%@�B�	��<�(�(�%�W�l�.B�.B�C�	��<�(�(r'rCr�c�*�|f}|jjr|jj|�}nd}i}|r|D�cgc]}|df��c}|d<|jjr
d|d<d|d<|jjd||d�|��Scc}w)NT�match_tests�verboseF�output_on_failure)�testsr�r))rT�rerun�get_match_testsr��create_worker_runtests)r$rCr�r�r��kwargsrjs       r%r�z#WorkerThread.create_worker_runtests�s�������=�=����-�-�7�7�	�B�K��K�!#���>I�$J�d�d�D�\�$J�F�=�!��=�=�*�*� $�F�9��*/�F�&�'�3�t�}�}�3�3�������	��	%Ks�B�worker_runtests�	stdout_fdc��tjswtjd��}tj
j
|�}	|j|||�}t	j|�}tj|�||fS|j||�}g}||fS#t	j|�}tj|�wxYw)N�test_python_)�prefix)r�is_wasir��mkdtemprt�path�abspathr��listdirr�rmtree)r$r�r�r�r��	tmp_filess      r%�
run_tmp_fileszWorkerThread.run_tmp_filess���
����&�&�n�=�G��g�g�o�o�g�.�G�
*��+�+�O�,5�w�@���J�J�w�/�	�� � ��)�
��#�#��'�'���C�G��I���#�#��
�J�J�w�/�	�� � ��)�s�B � ,Cr�c���|jd�	|j�j�S#t$r/}t	|j
d|��dtj���d}~wwxYw)NrzCannot read process stdout: )rDrE)�seek�read�strip�	ExceptionrBrCr�
WORKER_BUG)r$r�r|s   r%�read_stdoutzWorkerThread.read_stdout(sh�������	6��#�#�%�+�+�-�-���	6��d�n�n� <�S�E�B�%)�$)�$4�$4�6�
6��	6�s�1�	A)�*A$�$A)r�rDc��	|�"|jd�|j�}nn|jtjk(r&|jd�\}}}|j
�}n+|jd��5}|j�}ddd�s't|jd|tj���	tj|�}	|	|fS#1swY�LxYw#t$r1}d|��}t|j||tj���d}~wwxYw#t$r1}d|��}t|j||tj���d}~wwxYw)	Nr�
r�r�z$Failed to read worker process JSON: rGz
empty JSONz%Failed to parse worker process JSON: )r�r��	file_typerr��
rpartition�rstrip�openr�rBrCrr�r�	from_json)
r$r�r�rD�worker_json�_�json_fpr|r<r:s
          r%�	read_jsonzWorkerThread.read_json4sR��	6��'��!�!�!�$�*�/�/�1���$�$��(;�(;�;�)/�):�):�4�)@�&���;�������^�^�V�^�4�1��")�,�,�.�K�1���d�n�n�l�F�$)�$4�$4�6�
6�	6��)�)�+�6�F�����-1�1���	6�=�S�E�B�G��d�n�n�g�v�$)�$4�$4�6�
6��		6���	6�>�c�U�C�G��d�n�n�g�v�$)�$4�$4�6�
6��		6�sH�A9C#�;C�C#�>D �C �C#�#	D�,,D�D� 	E�),E�Ec
���tj�5}|j|�}|j|�\}}|j	||�}|j||j
��\}}|j|�}	|�'t|j|	dtj���|dk7r?t|�}
|
r|�d|
�d�}t|jd|��|	tj���|j|||	�\}}	ddd�rAd|�dt|��d	d
j!t#|����}	|z
}	j%�t'	�S#1swY�XxYw)N)rDr<rEr� (�)z
Exit code rGz

Warning -- z leaked temporary files (�): �, )�
contextlib�	ExitStackr�r�r�r�r�r�rBrCr�TIMEOUTr�
WORKER_FAILEDr��lenrh�sorted�set_env_changedr9)
r$rCr�r�r�r�r�r�r�rD�namer:�msgs
             r%�_runtestzWorkerThread._runtestVs���
�
!�
!�
#�	M�u��,�,�U�3�K�&*�&;�&;�E�&B�#�I�|�"�9�9�)�Y�O�O�"&�!3�!3�O�4?�4F�4F�4H�"J��G�Y��%�%�k�2�F���!�$�.�.��*.�(-�
�
�7�7��!�|�&�w�/���!(�	��D�6��3�G�!�$�.�.�J�w�i�2H�&�(-�(;�(;�=�=�"�^�^�I�|�V�L�N�F�F�-	M�0�!�!*��,��9�~�&�c�$�)�)�F�9�4E�*F�)G�I�C�
�c�M�F��"�"�$�!�&�&�1�1�?	M�	M�s�C/E�E$c��|jj}|jj}|js�		t	|j
�}tj�|_	||_
	|j|�}d|_
tj�|jz
|j_|j j#d|f�|jj%||�ry	|js��yy#t$rYywxYw#t$r}|j}Yd}~��d}~wwxYw#d|_
wxYw#t&$rYyt($r2|j j#dt+j,�f�YywxYw)NFT)rT�	fail_fast�fail_env_changedr]r.rUr-rdrerZrCr�rBrHr:�durationrV�put�	must_stopr@�
BaseException�	traceback�
format_exc)r$r�r�rCrHr|s      r%�runzWorkerThread.runxsC���M�M�+�+�	��=�=�9�9���-�-�
�� $�T�\�\� 2�I�#'�.�.�"2���!*���*� $�
�
�i� 8�I�&*�D�N�,0�N�N�,<�t���,N�	� � �)�������	� 2�3��#�#�-�-�i�9I�J��K�%�-�-��%�����#�.� #�
�
�I��.��&*�D�N���
�� �
�������y�';�';�'=� >�?��
�sl�D� E�1D�A0E�	D�E�D�E�	D1�D,�'D4�,D1�1D4�4	D=�=E�	F�7F�Fc	���|j}	|jt�y#tjt
f$r+}t
d|�dtt��d|���Yd}~yd}~wwxYw)NzFailed to wait for z completion (timeout=r�)r[r��WAIT_COMPLETED_TIMEOUTr�r�rzrr)r$rkr|s   r%r�zWorkerThread._wait_completed�si������	&��J�J�-�.���)�)�7�3�	&��/��v�6&�&5�6L�&M�%N�c� �G�%�
&�
&��	&�s�$�A(�!A#�#A(rZc��	|jd�|j�sytj�|z
}|j	d|�dt|����|tkDrtd|�dt|����y�~)Ng�?zWaiting for z thread for zFailed to join z in )rhrbrdrerYr�WAIT_KILLED_TIMEOUTr)r$rZrls   r%�wait_stoppedzWorkerThread.wait_stopped�sz����I�I�c�N��=�=�?�����!�J�.�B��H�H�|�D�6��o�b�6I�5J�K�L��'�'����v�T�/�"�:M�9N�O�P��r'�rRNr)!r2r3r4�intr&r>rmr}r1rrr�r�r�rr��tuplerr�rr��listr�r�rr�r9r�r�r��floatr�rKrLs@r%rNrNesd����#��|����'�#�'� =�8�04�,�^�,��,�%��n�,�8;�d�
�,�\�:�#7�#7��F��,)�j�&:�&:�)�u�X�v�X\�}�E\�?]�)�,���X��R`��$$�^�$�!$�$�).�s�T�z�4��=�/H�)I�$�.
6�v�
6�#�
6�  �8�  �6�D�=�  ��  �"'�
�C��"8�  �D 2�(� 2�/A� 2�D�:&��u���r'rN�workersrRc��g}|D]^}|j}|s�tj�|jz
}|tk\s�=|�dt|��d�}|j
|��`|sydt|��ddj|���S)Nr�r�z	running (r�r�)	rCrdrerZrrrcr�rh)r�r_�workerrCrl�texts      r%�get_runningr��s����G��!���$�$�	���
�^�^�
�� 1� 1�
1��
�"�"��[��?�2�#6�"7�q�9�D��N�N�4� �!���
�s�7�|�n�C��	�	�'�(:�';�<�<r'c
�r�eZdZdededededdf
d�Zdd�Zdd	�Z	de
dzfd
�Zdeddfd�Z
d
e
defd�Zdd�Zy)rQ�num_workersrT�logger�resultsrRNc��||_||_|j|_|j|_||_tj�|_|j�}t|�|_
|j|_|j�,t|jdz|jdz�|_
nd|_
d|_|jj�}|�t|j|�|_yy)Ng�?i,)r�rTrY�display_progressr��queue�QueuerV�
iter_testsrrUrX�minrWr��get_jobs)r$r�rTr�r�r#�jobss       r%r&zRunWorkers.__init__�s���&��� ��
��:�:��� &� 7� 7���$+���05���
����(�(�*�
�+�J�7����'�'����<�<�#�14�D�L�L�3�4F����W]�H]�0^�D��"&�D��26����}�}�%�%�'���� #�4�#3�#3�T�:�D��r'c�
�td|jdz�D�cgc]}t||���c}|_|jj�}|�
t
|d�}nd}t|j�}t|dd�}d|�d|�d|��}|jr2|d	t|j��d
t|j��d�z
}|j|�|jD]}|j��ycc}w)Nr	rjr��process�	processeszRun z in parallel using z worker z (timeout: z, worker timeout: r�)�ranger�rNr�rTr�rr�rrXrrWrY�start)r$�indexrr��nworkersrr�r�s        r%�
start_workerszRunWorkers.start_workers�s���%*�1�d�.>�.>��.B�%C�E�!�%�U�D�1�E����}�}�%�%�'�����$��'�E��E��t�|�|�$���8�Y��<�	��e�W�/���8�I�;�0���<�<��&�t�|�|�4�&�t�':�':�;�=�
>�C�	
����
��l�l�	�F��L�L�N�	��!Es�Dc��tj�}|jD]}|j��|jD]}|j	|��yr)rdrer�r1r�)r$rZr�s   r%�stop_workerszRunWorkers.stop_workers�sK���^�^�%�
��l�l�	�F��K�K�M�	��l�l�	,�F����
�+�	,r'c�,�|jj}|jdu}td�|jD��r>|rtjtd��	|jjt��S	|jjd��S#tj$rYnwxYw|s(t|j�}|r|j|�td�|jD��r���~#tj$rYywxYw)Nc3�<K�|]}|j����y�wr)rb)�.0r�s  r%�	<genexpr>z)RunWorkers._get_result.<locals>.<genexpr>s����?��&�/�/�#�?�s�T)�exitr�r)rT�pgorX�anyr��faulthandler�dump_traceback_later�MAIN_PROCESS_TIMEOUTrV�get�PROGRESS_UPDATEr��Emptyr�rY)r$r�use_faulthandlerr_s    r%�_get_resultzRunWorkers._get_result�s����m�m���� �L�L��4���?�$�,�,�?�?���1�1�2F�7;�=�
��{�{�����?�?�	��;�;�?�?�1�?�-�-���;�;�
��
���%�d�l�l�3����H�H�W�%��?�$�,�,�?�?��(�{�{�	��	�s$�B�C=�B2�1B2�=D�DrHc�v�|j}|jj}t|�}|jr|d|jzz
}n0|j
tk\r|s|dt|j
�zz
}|st|j�}|r|d|��z
}|j|j|�y)Nz (%s)z -- )r:rTrr>r<r�rrr�r�r��
test_index)r$rHr:rr�r_s      r%�display_resultzRunWorkers.display_results����!�!���m�m�����6�{������G�i�/�/�/�/�D��o�o�!2�2�3��G�o�f�o�o�>�>�>�D��!�$�,�,�/�G���$�w�i�(�(�����d�o�o�t�4r'�itemc��|drV|d}td|���tdtj��}|jj||j�|S|xjdz
c_|d}|j}|jj||j�|j|�|jjsd}n|jtjk7}|r|j}|r
t|d��|S)z&Returns True if test runner must stop.rr	zregrtest worker thread failed: z<regrtest worker>rGT)rp)rrrr�r��accumulate_resultrTrr:rr�rE�PASSEDr;rq)r$rr�r:rH�show_stdoutrDs       r%�_process_resultzRunWorkers._process_result)s�����7��a��J��;�J�<�H�I�� 3�5�;K�;K�L�F��L�L�*�*�6�4�=�=�A��M����1�����G�	��!�!�����&�&�v�t�}�}�=����I�&��}�}�.�.��K�"�<�<�5�<�<�7�K���,�,�F���f�D�)��
r'c��|jj}|jj}|j�d|_		|j�}|�n%|j
|�}|j||�rn�8|j�tj�|jj!�|j#�y#t$rt�d|j_Y�qwxYw#|j�tj�|jj!�|j#�wxYw)NrT)rTr�r�rrrr"r��KeyboardInterruptrqr��interruptedrXr�cancel_dump_traceback_laterrUr1r
)r$r�r�rr:s     r%r�zRunWorkers.runFs
���M�M�+�+�	��=�=�9�9���������	 ���'�'�)���<���-�-�d�3���#�#�I�/?�@����|�|�'��8�8�:�
�L�L���������!�	,��G�'+�D�L�L�$�	,���|�|�'��8�8�:�
�L�L��������s%�9C	�	$C0�-C3�/C0�0C3�3AD?r�)r2r3r4r�rr
r
r&rr
�QueueOutputrr9rrr"r�r)r'r%rQrQ�st��;�C�;�8�;��;�*5�;�:>�;�6�(,��[�4�/��:5�(:�5�t�5� �K��J��: r'rQ)Dr��dataclassesr�os.pathrtr�rvr�rrr�r rdr��typingrrrrjr�test.supportrrr�r
r:rrr�r
rTrrrr�singler�utilsrrrrrrrr�rrr�r�rrr�r�r�	dataclassr9r>�ExcStrr�r'r�r@rB�ThreadrNr�r�rQr)r'r%�<module>r1sX�������
��
�����'�'��.��%� �F�F�%�D�D�D�=�
���
���+�+�+�+�
 ����.�.�.�����#�#�,����T�$�/���0��

���G�E�N�$6�6�7�%���
�v�@U�:V�V��	��	��)��N�9�#�#�N�b
=��l�+�=��d�
�=�[ �[ r'

Zerion Mini Shell 1.0