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



���]"�@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�random�	randrange�	Exception�append�with_tracebackr�	get_ident�set)	�N�done�
done_tasks�errorsrr�x�e�finished�r�9/opt/alt/python35/lib64/python3.5/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@s.eZdZdd�Zdddd�ZdS)�FindercCs%d|_d|_tj�|_dS)Nr)�numcallsrr�Lock�lock)�selfrrr �__init__@s		zFinder.__init__Nc
CsG|j�|jd7_WdQRX|j}tjd�|d|_dS)Nr
g{�G�z�?)r)r'r�time�sleep)r*�name�path�targetrrrr �	find_specEs

	
zFinder.find_spec)�__name__�
__module__�__qualname__r+r1rrrr r&<sr&c@s"eZdZdddd�ZdS)�FlushingFinderNcCstjj�dS)N)�sys�path_importer_cache�clear)r*r.r/r0rrr r1TszFlushingFinder.find_spec)r2r3r4r1rrrr r5Ps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<dS)Nr)r<r6r:)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)r0�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�unittestZSkipTestr�Eventr�printr6r:�KeyErrorr8r,�	monotonicr
�range�waitr�assertFalseZ
assertTrue)r*�modname�t0Z	completedZdtZdbg_infor)rrrrr �check_parallel_module_initds6

	
z.ThreadedImportTests.check_parallel_module_initcCs|j�dS)N)rW)r*rrr �test_parallel_module_init�sz-ThreadedImportTests.test_parallel_module_initcCskt�}tjjd|�z7|j�|j|jd�|j|j|j�Wdtjj	|�XdS)Nr)
r&r6�	meta_path�insertrW�
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�)r1�ImportError)r/)r^rr �	path_hook�s
z?ThreadedImportTests.test_parallel_path_hooks.<locals>.path_hookrr`)r&r5r6�
path_hooksrZrYrr1rWr[r'r\rr])r*Zflushing_finderrbZnumtestsr)r^r �test_parallel_path_hooks�s		
z,ThreadedImportTests.test_parallel_path_hookscCsFytjd=Wntk
r"YnXddl}|j|jj�dS)Nztest.threaded_import_hangersr)r6r:rPZtest.threaded_import_hangersrTZthreaded_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#rrh)r#)rirr �	import_ba�sz<ThreadedImportTests.test_circular_imports.<locals>.import_bar0�a�b)�os�mkdirr�
addCleanup�shutilr	r6r/rZr]�circular_imports_modules�items�open�join�write�encoder�	importlib�invalidate_cachesrrD�startr\r)	r*rfr.�contents�frjrk�t1Zt2r)rir �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.pyrgzutf-8�__pycache__)r6r/rZrn�curdirrpr]rrtrvrwrrr	rxry�
__import__)r*�code�filenamer|rrr �test_side_effect_import�s

z+ThreadedImportTests.test_side_effect_importN)r2r3r4r=r>rWrXr_rdrer~r�rrrr r9Xs!

&r9cCsgd}ytj�}tjd�Wntk
r7YnXztt�Wd|dk	rbtj|�XdS)Ng�h㈵��>)r6�getswitchinterval�setswitchinterval�AttributeErrorrr9)Zold_switchintervalrrr �	test_main�s
r��__main__)�_imprKrnrxr6r,rqrMZtest.supportrrrrrrrr	r
rr!rrr&r5ZTestCaser9r�r2rrrr �<module>s*@�