Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/test/test_importlib/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/test/test_importlib/__pycache__/test_threaded_import.cpython-312.pyc

�

)Μgu%��P�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
mZddlmZmZmZddl
mZmZej*d��d	�Zd
ddd
d�ZGd�d�ZGd�d�ZGd�dej4�Zd�Zedk(rej<�yy)�N)�mock)�verbose)�forget�mock_register_at_fork)�TESTFN�unlink�rmtree)�
script_helper�threading_helperT)�modulec���	t|�dzr	ddl}ddl}nddl}ddl}|jdd�}|jtj��t|�|k(}|r|j�yy#t$r*}|j|j
d��Yd}~�sd}~wwxYw#|jtj��t|�|k(}|r|j�wwxYw)N�r��)
�len�modulefinder�random�	randrange�	Exception�append�with_traceback�	threading�	get_ident�set)	�N�done�
done_tasks�errorsrr�x�e�finisheds	         �E/usr/local/lib/python3.12/test/test_importlib/test_threaded_import.py�taskr#s�����z�?�Q���������Q��"��	���)�-�-�/�0��z�?�a�'����H�H�J����.��
�
�a�&�&�t�,�-�-��.��	���)�-�-�/�0��z�?�a�'����H�H�J��s*�1A8�8	B+� B&�!B.�&B+�+B.�.AC4zaif 1:
        import time
        time.sleep(%(delay)s)
        x = 'a'
        import C
        zaif 1:
        import time
        time.sleep(%(delay)s)
        x = 'b'
        import D
        zimport Bzimport A)�A�B�C�Dc��eZdZdZd�Zdd�Zy)�FinderzIA dummy finder to detect concurrent access to its find_spec()
    method.c�R�d|_d|_tj�|_y�Nr)�numcallsrr�Lock�lock��selfs r"�__init__zFinder.__init__Ds����
�����N�N�$��	�Nc���tj�sJ�|j5|xjdz
c_ddd�|j}tjd�|dz|_y#1swY�5xYw)Nrg{�G�z�?)�imp�	lock_heldr.r,r�time�sleep)r0�name�path�targetrs     r"�	find_speczFinder.find_specIsT���}�}����
�Y�Y��M�M�Q��M���F�F���
�
�4���Q����	�Y�s�A-�-A6�NN)�__name__�
__module__�__qualname__�__doc__r1r;�r2r"r)r)@s���%�
	r2r)c��eZdZdZdd�Zy)�FlushingFinderzMA dummy finder which flushes sys.path_importer_cache when it gets
    called.Nc�@�tjj�y�N)�sys�path_importer_cache�clear)r0r8r9r:s    r"r;zFlushingFinder.find_specXs�����%�%�'r2r<)r=r>r?r@r;rAr2r"rCrCTs���(r2rCc�b�eZdZd�Zd�Zed��Zd�Zd�Zd�Z	d�Z
d�Zed	��Zd
�Z
d�Zy)
�ThreadedImportTestsc�N�tjjdd�|_y�Nr)rF�modules�pop�
old_randomr/s r"�setUpzThreadedImportTests.setUp^s���+�+�/�/�(�D�9��r2c�X�|j�|jtjd<yyrL)rOrFrMr/s r"�tearDownzThreadedImportTests.tearDownas%���?�?�&�$(�O�O�C�K�K��!�'r2c����	�
�tj�rtjd��t	j
��dD�]�trtd�dd��dD]}	tj|=�g�
g�	�j�tj�}tj���	�
fd�t!��D��5	ddd��j#d	�}tj�|z
}trtd
|dzzdd�
�dt%�	��d���}|j'�
|�|j)||�ts��
td���y#t$rY��
wxYw#1swY��xYw)Nz"can't run when import lock is held)��2rTrUrTrU�Tryingzthreads ...� )�end)rrc3�\�K�|]#}tjt����f�����%y�w))r:�argsN)r�Threadr#)�.0�irrrrs  ����r"�	<genexpr>zAThreadedImportTests.check_parallel_module_init.<locals>.<genexpr>|s2�����0'�%���$�$�D��4��V�7U�V�V�%�s�),iXz%.1f msg@�@T)�flushrXzdone: �/zOK.)r4r5�unittest�SkipTestr�Eventr�printrFrM�KeyErrorrHr6�	monotonicr�
start_threads�range�waitr�assertFalse�
assertTrue)r0�mock_os�modname�t0�	completed�dt�dbg_inforrrrs       @@@@r"�check_parallel_module_initz.ThreadedImportTests.check_parallel_module_iniths9����=�=�?��#�#�$H�I�I���� ���A���h��=�c�:�5������G�,�6�
�F��J��J�J�L����!�B�!�/�/�0'�"�1�X�0'�'��'��	�	�'�*�I����!�B�&�B���i�2�c�6�*�$�C�@��(+�J���;�H����V�X�.��O�O�I�x�0���e��3�� �����'�'�s�#E �E0� 	E-�,E-�0E9	c�$�|j�yrE)rrr/s r"�test_parallel_module_initz-ThreadedImportTests.test_parallel_module_init�s���'�'�)r2c��t�}tjjd|�	|j	�|j|jd�|j|j|j�tjj|�y#tjj|�wxYwr+)
r)rF�	meta_path�insertrr�
assertGreaterr,�assertEqualr�remove)r0�finders  r"�test_parallel_meta_pathz+ThreadedImportTests.test_parallel_meta_path�s������
�
���Q��'�	)��+�+�-����v����2����V�X�X�v���7��M�M� � ��(��C�M�M� � ��(�s�AB�!B?c���t��t�}�fd�}tjj	d|�tj
j
|�	|jd�|j�}|j�jd�|j�j�j�tj
j|�tjj|�y#tj
j|�tjj|�wxYw)Nc�2���jd�t�)N�)r;�ImportError)r9r{s �r"�	path_hookz?ThreadedImportTests.test_parallel_path_hooks.<locals>.path_hook�s������R� ��r2rr)r)rCrF�
path_hooksrwrvrr;rrrxr,ryrrz)r0�flushing_finderr��numtestsr{s    @r"�test_parallel_path_hooksz,ThreadedImportTests.test_parallel_path_hooks�s�������)�*��	�	�����a��+��
�
���_�-�	-��%�%�b�)��6�6�8�H����v����2����V�X�X�v���7��M�M� � ��1��N�N�!�!�)�,��
�M�M� � ��1��N�N�!�!�)�,�s�A#C=�=AD=c��	tjd=ddl}|j	|j
jj�y#t$rY�?wxYw)Nz+test.test_importlib.threaded_import_hangersr)rFrMre�+test.test_importlib.threaded_import_hangersrj�test_importlib�threaded_import_hangersr)r0�tests  r"�test_import_hangersz'ThreadedImportTests.test_import_hangers�sM��	����I�J�	;�����,�,�D�D�K�K�L���	��	�s�A�	A�Ac��	�d}tjt�|jtj
t�tjjdt�|jtjjt�tj�D]|\}}|d|iz}ttjjt|dz�d�5}|j|jd��ddd�|jt |��~t#j$�g�	�	fd�}�	fd�}t'j(|�	�}t'j(|�	�}|j+�|j+�|j�|j�|j-t/�	�d
dh�y#1swY��xYw)Ng�?r�delay�.py�wb�utf-8c�F��ddl}�jt|dd��y�Nrr)r$r�getattr)r$�resultss �r"�	import_abz<ThreadedImportTests.test_circular_imports.<locals>.import_ab�������N�N�7�1�c�4�0�1r2c�F��ddl}�jt|dd��yr�)r%rr�)r%r�s �r"�	import_baz<ThreadedImportTests.test_circular_imports.<locals>.import_ba�r�r2)r:�a�b)�os�mkdirr�
addCleanup�shutilr	rFr9rwrz�circular_imports_modules�items�open�join�write�encoder�	importlib�invalidate_cachesrr[�startryr)
r0r�r8�contents�fr�r��t1�t2r�s
         @r"�test_circular_importsz)ThreadedImportTests.test_circular_imports�sC�����
���������
�
�v�.�������6�"����������0�6�<�<�>�N�D�(��7�E�"2�2�H��b�g�g�l�l�6�4�%�<�8�$�?�1��������0�1�@��O�O�F�D�)�	?�	�#�#�%���	2�	2��
�
�Y�
/��
�
�
�Y�
/��
���
�
���
�
���	�
���	�����W���S�z�2�%@�?�s�%!G�G	c��d}tjjdtj�|jtjjtj�tdz}t|d�5}|j|jd��ddd�|jt|�|jtt�|jtd�tj�t!j"�5t%t�ddd�tj&t=y#1swY��xYw#1swY�+xYw)Nz�if 1:
            import threading
            def target():
                import random
            t = threading.Thread(target=target)
            t.start()
            t.join()
            t = Nonerr�r�r��__pycache__)rFr9rwr��curdirr�rzrr�r�r�rrr	r�r�r�wait_threads_exit�
__import__rM)r0rl�code�filenamer�s     r"�test_side_effect_importz+ThreadedImportTests.test_side_effect_import�s�����	������2�9�9�%������������3��E�>��
�(�D�
!�Q�
�G�G�D�K�K��(�)�"������)������'�����
�.��#�#�%�
�
/�
/�
1��v��2��K�K���"�
!��2�
1�s�>!E�E�E�Ec��tjjtjjt�dd�}tj|�y)N�partialzcfimport.py�r�r9r��dirname�__file__r
�assert_python_ok�r0�fns  r"�'test_concurrent_futures_circular_importz;ThreadedImportTests.test_concurrent_futures_circular_import�s6��
�W�W�\�\�"�'�'�/�/�(�3�#�]�4���&�&�r�*r2c��tjjtjjt�dd�}tj|�y)Nr�zpool_in_threads.pyr�r�s  r"�)test_multiprocessing_pool_circular_importz=ThreadedImportTests.test_multiprocessing_pool_circular_import�s7��
�W�W�\�\�"�'�'�/�/�(�3�#�%9�;���&�&�r�*r2N)r=r>r?rPrRrrrrtr|r�r�r�r�r�r�rAr2r"rJrJ\sZ��:�4�����B*�)�-�.M�$3�L� �� �,+�+r2rJc�.�tj�}tjtjg|���	tj�}tjt
j|�tjd�y#t$rYywxYw)Ng�h㈵��>)	r�threading_setupra�addModuleCleanup�threading_cleanuprF�getswitchinterval�setswitchinterval�AttributeError)�thread_info�old_switchintervals  r"�setUpModuler�su��"�2�2�4�K����.�@�@�O�;�O�
� �2�2�4���!�!�#�"7�"7�9K�L����d�#���
��
�s�A
B�	B�B�__main__)�_impr4r�r�rFr6r�rrar�test.supportr�test.support.import_helperrr�test.support.os_helperrrr	r
r�requires_working_threadingr#r�r)rC�TestCaserJr�r=�mainrAr2r"�<module>r�s����	��
��
���� �D�;�;�8�+��+�+�4�8��0
�
�
�	���"��((�(�c+�(�+�+�c+�L
��z���H�M�M�O�r2

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists