Your IP : 216.73.216.85


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_threaded_import.cpython-35.opt-1.pyc



��Yf"�@s2ddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZe
d�Zdd�Zdddd	d
ddd
iZGdd�d�ZGdd�d�ZGdd�dej�Ze
dd��Zedkr.e�dS)�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	�XdS)N�r��)
�len�modulefinder�randomZ	randrange�	Exception�append�with_tracebackr�	get_ident�set)	�N�done�
done_tasks�errorsrr�x�eZfinished�r�>/opt/alt/python35/lib64/python3.5/test/test_threaded_import.py�tasks-r�Azaif 1:
        import time
        time.sleep(%(delay)s)
        x = 'a'
        import C
        �Bzaif 1:
        import time
        time.sleep(%(delay)s)
        x = 'b'
        import D
        �Czimport B�Dzimport Ac@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
CsG|j�|jd7_WdQRX|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<dS)Nr)r9r3r7)r'rrr�tearDown]szThreadedImportTests.tearDowncsstj�rtjd��tj��xEdD]=�trPtd�ddd�x7d	d
gD])}ytj	|=Wq]t
k
r�Yq]Xq]Wg�g��j�tj
�}t����fdd�t��D���WdQRX�jd�}tj
�|}tr%td|ddddd�dt���f}|j�|�|j||�tr.td�q.WdS)Nz"can't run when import lock is held��2rZTryingzthreads ...�end� rrc	3s3|])}tjdtd����f�VqdS)r,�argsN)r�Threadr)�.0�i)rrrrrr�	<genexpr>wszAThreadedImportTests.check_parallel_module_init.<locals>.<genexpr>�
�<z%.1f msg@�@�flushTzdone: %s/%szOK.)r<r=)r<r=r<r=r<r=iX)�imp�	lock_held�unittestZSkipTestrZEventr�printr3r7�KeyErrorr5r)Z	monotonicr
�range�waitr�assertFalseZ
assertTrue)r'�modnameZt0Z	completedZdtZdbg_infor)rrrrr�check_parallel_module_initds6

	
z.ThreadedImportTests.check_parallel_module_initcCs|j�dS)N)rQ)r'rrr�test_parallel_module_init�sz-ThreadedImportTests.test_parallel_module_initcCskt�}tjjd|�z7|j�|j|jd�|j|j|j�Wdtjj	|�XdS)Nr)
r$r3�	meta_path�insertrQ�
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+)rXrr�	path_hook�s
z?ThreadedImportTests.test_parallel_path_hooks.<locals>.path_hookrrZ)r$r2r3�
path_hooksrTrSrr-rQrUr%rVrrW)r'Zflushing_finderr\Znumtestsr)rXr�test_parallel_path_hooks�s		
z,ThreadedImportTests.test_parallel_path_hookscCsFytjd=Wntk
r"YnXddl}|j|jj�dS)Nztest.threaded_import_hangersr)r3r7rLZtest.threaded_import_hangersrOZthreaded_import_hangersr)r'Ztestrrr�test_import_hangers�s
z'ThreadedImportTests.test_import_hangersc	snd}tjt�|jtjt�tjjdt�|jtjj	t�x|t
j�D]n\}}|d|i}ttjj
t|d�d��}|j|jd��WdQRX|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!rrb)r!)rcrr�	import_ba�sz<ThreadedImportTests.test_circular_imports.<locals>.import_bar,�a�b)�os�mkdirr�
addCleanup�shutilr	r3r+rTrW�circular_imports_modules�items�open�join�write�encoder�	importlib�invalidate_cachesrrA�startrVr)	r'r`r*�contents�frdreZt1Zt2r)rcr�test_circular_imports�s*
%




z)ThreadedImportTests.test_circular_importsc
Cs�d}tjjdtj�|jtjjtj�td}t|d��}|j	|j
d��WdQRX|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.pyrazutf-8�__pycache__)r3r+rTrh�curdirrjrWrrnrprqrrr	rrrs�
__import__)r'�code�filenamervrrr�test_side_effect_import�s

z+ThreadedImportTests.test_side_effect_importN)r.r/r0r:r;rQrRrYr^r_rwr}rrrrr6Xs!

&r6cCsgd}ytj�}tjd�Wntk
r7YnXztt�Wd|dk	rbtj|�XdS)Ng�h㈵��>)r3�getswitchinterval�setswitchinterval�AttributeErrorrr6)Zold_switchintervalrrr�	test_main�s
r��__main__)�_imprHrhrrr3r)rkrJZtest.supportrrrrrrrr	r
rrrlr$r2ZTestCaser6r�r.rrrr�<module>s*@�