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.pyc

�
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
CsXtj�st�|j�|jd7_WdQX|j}tjd�|d|_dS)Nr
g{�G�z�?)�imp�	lock_held�AssertionErrorr&r%r�timeZsleep)r'�name�path�targetrrrr�	find_specEs
	
zFinder.find_spec)�__name__�
__module__�__qualname__�__doc__r(r0rrrrr$<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/rrrr0TszFlushingFinder.find_spec)r1r2r3r4r0rrrrr5Psr5c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�ThreadedImportTestscCstjjdd�|_dS)Nr)r6�modules�pop�
old_random)r'rrr�setUpZszThreadedImportTests.setUpcCs&|jdk	r"|jtjd<ndS)Nr)r<r6r:)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@)r)r*�unittestZSkipTestrZEventr�printr6r:�KeyErrorr8r
�rangeZ
assertTrue�wait�assertFalse)r'�modnamer)rrrrr�check_parallel_module_initds*

	

z.ThreadedImportTests.check_parallel_module_initcCs|j�dS)N)rP)r'rrr�test_parallel_module_initsz-ThreadedImportTests.test_parallel_module_initcCskt�}tjjd|�z7|j�|j|jd�|j|j|j�Wdtjj	|�XdS)Nr)
r$r6�	meta_path�insertrP�
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�)r0�ImportError)r.)rWrr�	path_hook�s
z?ThreadedImportTests.test_parallel_path_hooks.<locals>.path_hookrrY)r$r5r6�
path_hooksrSrRrr0rPrTr%rUrrV)r'Zflushing_finderr[Znumtestsr)rWr�test_parallel_path_hooks�s		
z,ThreadedImportTests.test_parallel_path_hookscCsFytjd=Wntk
r"YnXddl}|j|jj�dS)Nztest.threaded_import_hangersr)r6r:rKZtest.threaded_import_hangersrNZthreaded_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!rra)r!)rbrr�	import_ba�sz<ThreadedImportTests.test_circular_imports.<locals>.import_bar/�a�b)�os�mkdirr�
addCleanup�shutilr	r6r.rSrV�circular_imports_modules�items�open�join�write�encoder�	importlib�invalidate_cachesrrD�startrUr)	r'r_r-�contents�frcrdZt1Zt2r)rbr�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__)r6r.rSrg�curdirrirVrrmrorprrr	rqrr�
__import__)r'�code�filenamerurrr�test_side_effect_import�s

z+ThreadedImportTests.test_side_effect_importN)r1r2r3r=r>rPrQrXr]r^rvr|rrrrr9Xs

&r9cCsjd}ytj�}tjd�Wntk
r7YnXztt�Wd|dk	retj|�nXdS)Ng�h㈵��>)r6�getswitchinterval�setswitchinterval�AttributeErrorrr9)Zold_switchintervalrrr�	test_main�s
r��__main__)�_impr)rgrqr6r,rjrIZtest.supportrrrrrrrr	r
rrrkr$r5ZTestCaser9r�r1rrrr�<module>s(@
�