Your IP : 216.73.217.129


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-2.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@seZdZdd�Zddd�ZdS)�FindercCsd|_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__r,r2rrrrr&Csr&c@seZdZddd�ZdS)�FlushingFinderNcCstj��dS�N)�sys�path_importer_cache�clear)r+r/r0r1rrrr2[szFlushingFinder.find_spec)NN)r3r4r5r2rrrrr6Wsr6c@s\eZdZdd�Zdd�Zedd��Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zedd��ZdS)�ThreadedImportTestscCstj�dd�|_dS�Nr)r8�modules�pop�
old_randomr*rrr�setUpaszThreadedImportTests.setUpcCs|jdk	r|jtjd<dSr<)r?r8r=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)��2rBrCrBrCZTryingzthreads ...� )�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)�flushrEzdone: %s/%szOK.)�imp�	lock_held�unittestZSkipTestrZEventr�printr8r=�KeyErrorr:r-�	monotonicr
�range�waitr�assertFalseZ
assertTrue)r+�mock_os�modnameZt0Z	completedZdtZdbg_inforrJr�check_parallel_module_initks8
�


z.ThreadedImportTests.check_parallel_module_initcCs|��dSr7)rXr*rrr�test_parallel_module_init�sz-ThreadedImportTests.test_parallel_module_initc	CsRt�}tj�d|�z*|��|�|jd�|�|j	|j�W5tj�|�XdSr')
r&r8�	meta_path�insert�removerX�
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_hookrra)r&r6r8�
path_hooksr[rZrr\r2rXr]r(r^r)r+Zflushing_finderrdZnumtestsrrcr�test_parallel_path_hooks�s
z,ThreadedImportTests.test_parallel_path_hookscCs<ztjd=Wntk
r YnXddl}|�|jj�dS)Nztest.threaded_import_hangersr)r8r=rQZtest.threaded_import_hangersrUZthreaded_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��dSrl)r#rrm)r#rnrr�	import_ba�sz<ThreadedImportTests.test_circular_imports.<locals>.import_ba)r1�a�b)�os�mkdirr�
addCleanup�shutilr	r8r0r[r\�circular_imports_modules�items�open�join�write�encoder�	importlib�invalidate_cachesrrG�startr^r)	r+rhr/�contents�frorp�t1�t2rrnr�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 = Nonerrirjrk�__pycache__)r8r0r[rs�curdirrur\rryr{r|rrr	r}r~�
__import__r=)r+rV�code�filenamer�rrr�test_side_effect_import�sz+ThreadedImportTests.test_side_effect_importN)
r3r4r5r@rAr!rXrYr`rfrgr�r�rrrrr;_s
!

&r;c	CsVd}zt��}t�d�Wntk
r.YnXztt�W5|dk	rPt�|�XdS)Ng�h㈵��>)r8�getswitchinterval�setswitchinterval�AttributeErrorrr;)Zold_switchintervalrrr�	test_main�sr��__main__)�_imprMrsr}r8r-rvrrOrZtest.supportrrrrrrr	r
rr!rwr&r6ZTestCaser;r�r3rrrr�<module>s0(
�