Your IP : 216.73.216.213


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_threaded_import.cpython-38.opt-1.pyc

U

i�f�#�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZdd�Zdd�Zdd	d
dd�ZGd
d�d�ZGdd�d�ZGdd�dej�Zedd��Zedkr�e�dS)�N)�mock)�verbose�run_unittest�TESTFN�reap_threads�forget�unlink�rmtree�
start_threadsc	
Cs�zvz>t|�dr"ddl}ddl}nddl}ddl}|�dd�}Wn2tk
rr}z|�|�	d��W5d}~XYnXW5|�t���t|�|k}|r�|��XdS)N�r��)
�append�	threading�	get_ident�len�set�modulefinder�randomZ	randrange�	Exception�with_traceback)	�N�done�
done_tasks�errorsZfinishedrr�x�e�r�>/opt/alt/python38/lib64/python3.8/test/test_threaded_import.py�tasks
&rcCstjddd�|�S)Nzos.register_at_forkT)Zcreate)rZpatch)�funcrrr�mock_register_at_fork)sr!zaif 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@s"eZdZdZdd�Zddd�ZdS)�FinderzIA dummy finder to detect concurrent access to its find_spec()
    method.cCsd|_d|_t��|_dS�Nr)�numcallsrrZLock�lock��selfrrr�__init__GszFinder.__init__Nc	Cs>|j�|jd7_W5QRX|j}t�d�|d|_dS)Nrg{�G�z�?)r)r(r�time�sleep)r+�name�path�targetrrrr�	find_specLs

zFinder.find_spec)NN)�__name__�
__module__�__qualname__�__doc__r,r2rrrrr&Csr&c@seZdZdZddd�ZdS)�FlushingFinderzMA dummy finder which flushes sys.path_importer_cache when it gets
    called.NcCstj��dS�N)�sys�path_importer_cache�clear)r+r/r0r1rrrr2[szFlushingFinder.find_spec)NN)r3r4r5r6r2rrrrr7Wsr7c@s\eZdZdd�Zdd�Zedd��Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zedd��ZdS)�ThreadedImportTestscCstj�dd�|_dS�Nr)r9�modules�pop�
old_randomr*rrr�setUpaszThreadedImportTests.setUpcCs|jdk	r|jtjd<dSr=)r@r9r>r*rrr�tearDownds
zThreadedImportTests.tearDownc
st��rt�d��t���dD]�tr6td�ddd�dD]&}ztj	|=Wq:t
k
r^Yq:Xq:g�g����t�
�}t����fdd	�t��D���W5QRX��d
�}t�
�|}tr�td|dd
dd�dt���f}|��|�|�||�trtd�qdS)Nz"can't run when import lock is held)��2rCrDrCrDZTryingzthreads ...� )�end)rrc3s$|]}tjt����fd�VqdS))r1�argsN)r�Threadr)�.0�i�rrrrrr�	<genexpr>s�
�zAThreadedImportTests.check_parallel_module_init.<locals>.<genexpr>iXz%.1f msg@�@T)�flushrFzdone: %s/%szOK.)�imp�	lock_held�unittestZSkipTestrZEventr�printr9r>�KeyErrorr;r-�	monotonicr
�range�waitr�assertFalseZ
assertTrue)r+�mock_os�modnameZt0Z	completedZdtZdbg_inforrKr�check_parallel_module_initks8
�


z.ThreadedImportTests.check_parallel_module_initcCs|��dSr8)rYr*rrr�test_parallel_module_init�sz-ThreadedImportTests.test_parallel_module_initc	CsRt�}tj�d|�z*|��|�|jd�|�|j	|j�W5tj�|�XdSr')
r&r9�	meta_path�insert�removerY�
assertGreaterr(�assertEqualr)r+�finderrrr�test_parallel_meta_path�sz+ThreadedImportTests.test_parallel_meta_pathc	s�t��t�}�fdd�}tj�d|�tj�|�z4|�d�|�	�}|�
�jd�|��j
�j�W5tj�|�tj�|�XdS)Ncs��d�t�dS)N�)r2�ImportError)r0�r`rr�	path_hook�s
z?ThreadedImportTests.test_parallel_path_hooks.<locals>.path_hookrrb)r&r7r9�
path_hooksr\r[rr]r2rYr^r(r_r)r+Zflushing_finderreZnumtestsrrdr�test_parallel_path_hooks�s
z,ThreadedImportTests.test_parallel_path_hookscCs<ztjd=Wntk
r YnXddl}|�|jj�dS)Nztest.threaded_import_hangersr)r9r>rRZtest.threaded_import_hangersrVZthreaded_import_hangersr)r+Ztestrrr�test_import_hangers�sz'ThreadedImportTests.test_import_hangersc	
sd}t�t�|�tjt�tj�dt�|�tjj	t�t
��D]T\}}|d|i}ttj�
t|d�d��}|�|�d��W5QRX|�t|�qBt��g��fdd�}�fd	d
�}tj|d�}tj|d�}|��|��|�
�|�
�|�t��dd
h�dS)Ng�?r�delay�.py�wb�utf-8csddl}��t|dd��dS�Nrr)r"r�getattr)r"�Zresultsrr�	import_ab�sz<ThreadedImportTests.test_circular_imports.<locals>.import_abcsddl}��t|dd��dSrm)r#rrn)r#rorr�	import_ba�sz<ThreadedImportTests.test_circular_imports.<locals>.import_ba)r1�a�b)�os�mkdirr�
addCleanup�shutilr	r9r0r\r]�circular_imports_modules�items�open�join�write�encoder�	importlib�invalidate_cachesrrH�startr_r)	r+rir/�contents�frprq�t1�t2rror�test_circular_imports�s*
z)ThreadedImportTests.test_circular_importsc	Cs�d}tj�dtj�|�tjjtj�td}t|d��}|�	|�
d��W5QRX|�t|�|�tt�|�t
d�t��tt�tjt=dS)Nz�if 1:
            import threading
            def target():
                import random
            t = threading.Thread(target=target)
            t.start()
            t.join()
            t = Nonerrjrkrl�__pycache__)r9r0r\rt�curdirrvr]rrzr|r}rrr	r~r�
__import__r>)r+rW�code�filenamer�rrr�test_side_effect_import�sz+ThreadedImportTests.test_side_effect_importN)
r3r4r5rArBr!rYrZrargrhr�r�rrrrr<_s
!

&r<c	CsVd}zt��}t�d�Wntk
r.YnXztt�W5|dk	rPt�|�XdS)Ng�h㈵��>)r9�getswitchinterval�setswitchinterval�AttributeErrorrr<)Zold_switchintervalrrr�	test_main�sr��__main__)�_imprNrtr~r9r-rwrrPrZtest.supportrrrrrrr	r
rr!rxr&r7ZTestCaser<r�r3rrrr�<module>s0(
�