Sindbad~EG File Manager
�
'Μgw#���ddlZddlZddlZddlmZddlmZddlZddl Z ddl
Z
ddlZddlmZejd��dZdZej �Zd �ZGd
�dej&�ZGd�d
e�ZGd�d�ZGd�de�ZGd�dej0�ZGd�dej&�Zedk(rej6�yy)�N)�support)�threading_helper)�
lock_testsT)�module�
�c�r�tjrt5t|�ddd�yy#1swYyxYw)z2Helper function for printing out debugging output.N)r�verbose�_print_mutex�print)�args �-/usr/local/lib/python3.12/test/test_thread.py�
verbose_printrs%�����
��#�J��\��
�\�s�-�6c��eZdZd�Zy)�BasicThreadTestc�b�tj�|_|jj�tj�|_tj�|_d|_d|_d|_tj�}|jtjg|���y�Nr)
�thread�
allocate_lock�
done_mutex�acquire�
running_mutex�random_mutex�created�running�
next_identr�threading_setup�
addCleanup�threading_cleanup)�self�keys r�setUpzBasicThreadTest.setUps��� �.�.�0��������!�#�1�1�3���"�0�0�2�������������.�.�0������(�:�:�A�S�A�N)�__name__�
__module__�__qualname__r"�r#rrrs��
Br#rc�z�eZdZd�Zd�Zd�Zd�Zeje jdvd�d��Zd�Zd �Z
y
)�ThreadRunningTestsc�J�|j5|xjdz
c_td|jz�tj|j
|jf�|xjdz
c_|xjdz
c_ddd�y#1swYyxYw)N�zcreating task %s)rrrr�start_new_thread�taskrr�r s r�newtaskzThreadRunningTests.newtask,sn��
�
�
��O�O�q� �O��,�t���>�?��#�#�D�I�I����/A�B��L�L�A��L��L�L�A��L� �
�
�s�BB�B"c ���|j5tj�dz}ddd�td|�dtdz��d��t j
|�td|z�|j5|xjdzc_|jtk(r)|jdk(r|jj�ddd�y#1swY��xYw#1swYyxYw) N���@�task � will run for ���.A�usztask %s doner+r)r�randomr�round�time�sleeprrr�NUMTASKSr�release)r �ident�delays rr-zThreadRunningTests.task4s���
�
�
��M�M�O�g�-�E���U�E�%��)�<L�M�N��
�
�5���n�u�,�-�
�
�
��L�L�A��L��|�|�x�'�D�L�L�A�,=����'�'�)� �
��
��
�
�s�C�:AC!�C�!C*c��tj�5tt�D]}|j ��td�|jj�td�ddd�y#1swYyxYw)Nz waiting for tasks to complete...�all tasks done)r�wait_threads_exit�ranger:r/rrr�r �is r�test_starting_threadsz(ThreadRunningTests.test_starting_threads?sS��
�
/�
/�
1��8�_������%��<�=��O�O�#�#�%��*�+�
2�
1�
1�s�AA3�3A<c���|jtj�dd�tjd�|jtj�dd�y)Nrzinitial stack size is not 0zstack_size not reset to default)�assertEqualr�
stack_sizer.s r�test_stack_sizez"ThreadRunningTests.test_stack_sizeHsH������*�*�,�a�1N�O����!������*�*�,�a�1R�Sr#)�nt�posixztest meant for nt and posixc��� tjd�d}dD]M}tj|�|j
tj�|||z�td|z��OdD]�}td|z�d |_d |_tj�5tt�D]}|j��td
�|jj�td�ddd���tjd �y#t$rtd�Y��tj$r|jd�Y��;wxYw#1swY��xYw)Niz3caught expected ValueError setting stack_size(4096)z4platform does not support changing thread stack sizez&stack_size(%d) failed - should succeed)��rzsuccessfully set stack_size(%d))rLrMztrying stack_size = (%d)rz!waiting for all tasks to completer?)rrG�
ValueErrorr�error�skipTestrFrrrr@rAr:r/rr)r �fail_msg�tssrCs r�test_nt_and_posix_stack_sizez/ThreadRunningTests.test_nt_and_posix_stack_sizeOs,�� "����d�#�<��(�C����c�"����V�.�.�0�#�x�#�~�F��;�c�A�B�)�
&�C��4�s�:�;��D�O��D�L�!�3�3�5��x��A��L�L�N�)��A�B����'�'�)��.�/�
6�5� &� ���!���3� 0��/�
0��|�|� "��M�M�!�
"� "��6�5�s$�D� AE�E�,#E�E�E c������tj�}tj���j�g���fd�}t j
�5tj|d�tjtj�D]}�s�n|jtj�|dz��j�g�tj|�fd��}~tjtj�D]}�rntj��|jtj�|�ddd�y#1swYyxYw)Nc�h���jd��j��j�y�N)�appendrr;)�mut�starteds��rr-z,ThreadRunningTests.test__count.<locals>.taskus!����N�N�4� ��K�K�M��K�K�Mr#r'r+c�&���jd�SrV)rW)�_�dones �r�<lambda>z0ThreadRunningTests.test__count.<locals>.<lambda>�s���T�[�[��->r#)r�_countrrrr@r,r�sleeping_retry�LONG_TIMEOUTrFr;�weakref�ref�
gc_collect)r �origr-r[�wrr\rXrYs @@@r�test__countzThreadRunningTests.test__countns����}�}����"�"�$�����
��� �
�
/�
/�
1��#�#�D�"�-��+�+�G�,@�,@�A����B�
���V�]�]�_�d�Q�h�7�
�K�K�M�
�D����T�#>�?�B���+�+�G�,@�,@�A�����"�"�$�B�
���V�]�]�_�d�3�+2�
1�
1�s�?E�B:E�E$c����fd�}tj��tj�5}t j
�5�j
�tj|d��j
�ddd�|jt|jj�d�|j|jj|�|j|jjd�|j|jj �ddd�y#1swY��xYw#1swYyxYw)Nc�:���j�td��)N�task failed)r;rN)rYs�rr-z:ThreadRunningTests.test_unraisable_exception.<locals>.task�s����O�O���]�+�+r#r'riz&Exception ignored in thread started by)rrr�catch_unraisable_exceptionrr@rr,rF�str�
unraisable� exc_value�assertIs�object�err_msg�assertIsNotNone�
exc_traceback)r r-�cmrYs @r�test_unraisable_exceptionz,ThreadRunningTests.test_unraisable_exception�s���� ,��&�&�(��
�
/�
/�
1�R�!�3�3�5����!��'�'��b�1����!�6�
���S����!8�!8�9�=�I��M�M�"�-�-�.�.��5����R�]�]�2�2�E�
G�� � ����!<�!<�=�2�
1�5�5��2�
1�s$�D8�7D,�;B(D8�,D5 �1D8�8EN)r$r%r&r/r-rDrH�unittest�skipIf�os�namerSrfrtr'r#rr)r)*sN��� *�,�T��X�_�_�R�W�W�O�3�5R�S��T��<!4�F>r#r)c��eZdZd�Zd�Zy)�Barrierc��||_d|_tj�|_tj�|_|j
j
�yr)�num_threads�waitingrr�
checkin_mutex�checkout_mutexr)r r|s r�__init__zBarrier.__init__�sE��&������$�2�2�4���$�2�2�4������#�#�%r#c��|jj�|jdz|_|j|jk(r/|jdz
|_|jj�y|jj�|jj�|jdz
|_|jdk(r|jj�y|jj�y)Nr+r)r~rr}r|rr;r.s r�enterz
Barrier.enter�s������"�"�$��|�|�a�'����<�<�4�+�+�+��+�+�a�/�D�L����'�'�)�����"�"�$����#�#�%��|�|�a�'����<�<�1�����&�&�(�����#�#�%r#N)r$r%r&r�r�r'r#rrzrz�s��&�&r#rzc��eZdZd�Zd�Zy)�BarrierTestc�^�tj�5tt�|_t|_t
t�D]#}tj|j|f��%td�|jj�td�ddd�y#1swYyxYw)Nzwaiting for tasks to endz
tasks done)
rr@rzr:�barrrArr,�task2rrrrBs r�test_barrierzBarrierTest.test_barrier�sr��
�
/�
/�
1��x�(�D�H�#�D�L��8�_���'�'��
�
�Q�D�9�%��4�5��O�O�#�#�%��,�'�2�
1�
1�s�BB#�#B,c
�H�tt�D]�}|dk(rd}n,|j5tj�dz}ddd�t d|�dtdz��d��t
j|�t d|�d|���|jj�t d|z���|j5|xjd zc_|jdk(}ddd�r|jj�yy#1swY��xYw#1swY�3xYw)
Nrr1r2r3r4r5z
entering ztask %s leaving barrierr+)rA�NUMTRIPSrr6rr7r8r9r�r�rrrr;)r r<rCr=�finisheds rr�zBarrierTest.task2�s����x��A���z����&�&�"�M�M�O�g�5�E�'�� �%����"4�6�
7��J�J�u���5�!�<�=��H�H�N�N���3�e�;�<�!��
�
��L�L�A��L��|�|�q�(�H� ���O�O�#�#�%��'�&�� �
�s�D�%D�D �D!N)r$r%r&r�r�r'r#rr�r��s��(�&r#r�c�$�eZdZejZy)� LockTestsN)r$r%r&rr�locktyper'r#rr�r��s
���#�#�Hr#r�c�d�eZdZd�Zej
�ejd���Zd�Z y)�TestForkInThreadc�F�tj�\|_|_yrV)rw�pipe�read_fd�write_fdr.s rr"zTestForkInThread.setUp�s��&(�g�g�i�#���d�mr#c���d��fd�}tj�5tj||j|j
f�|j
tj|jd�d�tj|j
�ddd�|j��tj�d��y#1swY�2xYw)Nc�^��tjtd��5tj�x�r
ddd�y ddd� tj
|�tj|d�tjd�y#1swY�KxYw#tjd�wxYw)N�ignore)�category�action�OKr)�warnings�catch_warnings�DeprecationWarningrw�fork�close�write�_exit)r�r��pids �r�fork_threadz7TestForkInThread.test_forkinthread.<locals>.fork_thread�s�����(�(�2D�08�:��7�7�9�$�C�$��:�:�%�:�
�����!�����5�)������:�:�������s�B �+B� B�B,�r�r)�exitcode)
rr@rr,r�r�rFrw�readr�rqr�wait_process)r r�r�s @r�test_forkinthreadz"TestForkInThread.test_forkinthread�s������ �$�
/�
/�
1��#�#�K�$�,�,��
�
�1N�O����R�W�W�T�\�\�1�5�u�=��H�H�T�]�]�#�2�
���S�!����S�1�-�
2�
1�s�A<C
�
Cc�� tj|j� tj|j�y#t$rY�,wxYw#t$rYywxYwrV)rwr�r��OSErrorr�r.s r�tearDownzTestForkInThread.tearDown sS�� ��H�H�T�\�\�"� ��H�H�T�]�]�#�� � �� ��
� �� �s"�A�A� A�
A� A�AN)
r$r%r&r"r�
requires_forkr�reap_threadsr�r�r'r#rr�r��s9��0��W�����"�"�.�#��.�: r#r��__main__)rwrur6�testr�test.supportr�_threadrr8r�rar�requires_working_threadingr:r�rrr�TestCaserr)rzr�r�r�r$�mainr'r#r�<module>r�s��� ��
��)������+��+�+�4�8�
����#�v�#�#�%���B�h�'�'�B�w>��w>�t&�&�2#&�/�#&�J$�
�$�$�$�,�x�(�(�,�^�z���H�M�M�O�r#
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists