Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_threaded_import.cpython-34.pyo

�
f f!�@s9ddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZe
d�Zdd�Zidd6dd	6d
d6dd
6ZGdd�d�ZGdd�d�ZGdd�dej�Ze
dd��Zedkr5e�ndS)�N)	�verbose�
import_module�run_unittest�TESTFN�reap_threads�forget�unlink�rmtree�
start_threads�	threadingc	Cs�z�yYt|�dr1ddl}ddl}nddl}ddl}|jdd�}Wn;tk
r�}z|j|jd��WYdd}~XnXWd|jtj��t|�|k}|r�|j	�nXdS)N�r��)
�len�modulefinder�randomZ	randrange�	Exception�append�with_tracebackr�	get_ident�set)	�N�done�
done_tasks�errorsrr�x�eZfinished�r�>/opt/alt/python34/lib64/python3.4/test/test_threaded_import.py�tasks-rzaif 1:
        import time
        time.sleep(%(delay)s)
        x = 'a'
        import C
        �Azaif 1:
        import time
        time.sleep(%(delay)s)
        x = 'b'
        import D
        �Bzimport B�Czimport A�Dc@s4eZdZdZdd�Zdddd�ZdS)�FinderzIA dummy finder to detect concurrent access to its find_spec()
    method.cCs%d|_d|_tj�|_dS)Nr)�numcallsrrZLock�lock)�selfrrr�__init__@s		zFinder.__init__Nc
CsF|j�|jd7_WdQX|j}tjd�|d|_dS)Nr
g{�G�z�?)r&r%r�timeZsleep)r'�name�path�targetrrrr�	find_specEs

	
zFinder.find_spec)�__name__�
__module__�__qualname__�__doc__r(r-rrrrr$<sr$c@s(eZdZdZdddd�ZdS)�FlushingFinderzMA dummy finder which flushes sys.path_importer_cache when it gets
    called.NcCstjj�dS)N)�sys�path_importer_cache�clear)r'r*r+r,rrrr-TszFlushingFinder.find_spec)r.r/r0r1r-rrrrr2Psr2c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ThreadedImportTestscCstjjdd�|_dS)Nr)r3�modules�pop�
old_random)r'rrr�setUpZszThreadedImportTests.setUpcCs&|jdk	r"|jtjd<ndS)Nr)r9r3r7)r'rrr�tearDown]szThreadedImportTests.tearDownc
stj�rtjd��ntj��x�dD]��trVtd�ddd�nx7d	d
gD])}ytj	|=Wqct
k
r�YqcXqcWg�g��j�t����fdd�t
��D���WdQX|j�jd
��|j��tr1td�q1q1WdS)Nz"can't run when import lock is held��2rZTryingzthreads ...�end� rrc	3s3|])}tjdtd����f�VqdS)r,�argsN)r�Threadr)�.0�i)rrrrrr�	<genexpr>vszAThreadedImportTests.check_parallel_module_init.<locals>.<genexpr>�<zOK.)r<r=)r<r=r<r=r<r=)�imp�	lock_held�unittestZSkipTestrZEventr�printr3r7�KeyErrorr5r
�rangeZ
assertTrue�wait�assertFalse)r'�modnamer)rrrrr�check_parallel_module_initds*

	

z.ThreadedImportTests.check_parallel_module_initcCs|j�dS)N)rO)r'rrr�test_parallel_module_initsz-ThreadedImportTests.test_parallel_module_initcCskt�}tjjd|�z7|j�|j|jd�|j|j|j�Wdtjj	|�XdS)Nr)
r$r3�	meta_path�insertrO�
assertGreaterr%�assertEqualr�remove)r'�finderrrr�test_parallel_meta_path�s	
z+ThreadedImportTests.test_parallel_meta_pathcs�t��t�}�fdd�}tjjd|�tjj|�zF|jd�|j�}|j	�j
d�|j�j�j
�Wdtjj
|�tjj
|�XdS)Ncs�jd�t�dS)N�)r-�ImportError)r+)rVrr�	path_hook�s
z?ThreadedImportTests.test_parallel_path_hooks.<locals>.path_hookrrX)r$r2r3�
path_hooksrRrQrr-rOrSr%rTrrU)r'Zflushing_finderrZZnumtestsr)rVr�test_parallel_path_hooks�s		
z,ThreadedImportTests.test_parallel_path_hookscCsFytjd=Wntk
r"YnXddl}|j|jj�dS)Nztest.threaded_import_hangersr)r3r7rJZtest.threaded_import_hangersrMZthreaded_import_hangersr)r'Ztestrrr�test_import_hangers�s
z'ThreadedImportTests.test_import_hangersc	snd}tjt�|jtjt�tjjdt�|jtjj	t�x|t
j�D]n\}}|i|d6}ttjj
t|d�d��}|j|jd��WdQX|jt|�q\Wtj�g��fdd�}�fd	d
�}tjd|�}tjd|�}|j�|j�|j
�|j
�|jt��dd
h�dS)Ng�?r�delayz.py�wbzutf-8cs)ddl}�jt|dd��dS)Nrr)r r�getattr)r )�resultsrr�	import_ab�sz<ThreadedImportTests.test_circular_imports.<locals>.import_abcs)ddl}�jt|dd��dS)Nrr)r!rr`)r!)rarr�	import_ba�sz<ThreadedImportTests.test_circular_imports.<locals>.import_bar,�a�b)�os�mkdirr�
addCleanup�shutilr	r3r+rRrU�circular_imports_modules�items�open�join�write�encoder�	importlib�invalidate_cachesrrA�startrTr)	r'r^r*�contents�frbrcZt1Zt2r)rar�test_circular_imports�s*
%




z)ThreadedImportTests.test_circular_importsc
Cs�d}tjjdtj�|jtjjtj�td}t|d��}|j	|j
d��WdQX|jt|�|jtt�|jt
d�tj�tt�dS)Nz�if 1:
            import threading
            def target():
                import random
            t = threading.Thread(target=target)
            t.start()
            t.join()rz.pyr_zutf-8�__pycache__)r3r+rRrf�curdirrhrUrrlrnrorrr	rprq�
__import__)r'�code�filenamertrrr�test_side_effect_import�s

z+ThreadedImportTests.test_side_effect_importN)r.r/r0r:r;rOrPrWr\r]rur{rrrrr6Xs

&r6cCsjd}ytj�}tjd�Wntk
r7YnXztt�Wd|dk	retj|�nXdS)Ng�h㈵��>)r3�getswitchinterval�setswitchinterval�AttributeErrorrr6)Zold_switchintervalrrr�	test_main�s
r�__main__)�_imprFrfrpr3r)rirHZtest.supportrrrrrrrr	r
rrrjr$r2ZTestCaser6rr.rrrr�<module>s(@
�