HEX
Server: LiteSpeed
System: Linux server.nevid-deploma.com 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
User: smilepac (1037)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/cppython/lib/python3.8/test/__pycache__/test_threaded_import.cpython-38.opt-2.pyc
U

.D�g�#�@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�random�	randrange�	Exception�with_traceback)	�N�done�
done_tasks�errors�finishedrr�x�e�r�8/opt/cppython/lib/python3.8/test/test_threaded_import.py�tasks
&r!cCstjddd�|�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)�numcallsrr�Lock�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/r5rrrr r(Csr(c@seZdZddd�ZdS)�FlushingFinderNcCstj��dS�N)�sys�path_importer_cache�clear)r.r2r3r4rrr r5[szFlushingFinder.find_spec)NN)r6r7r8r5rrrr r9Wsr9c@s\eZdZdd�Zdd�Zedd��Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zedd��ZdS)�ThreadedImportTestscCstj�dd�|_dS�Nr)r;�modules�pop�
old_randomr-rrr �setUpaszThreadedImportTests.setUpcCs|jdk	r|jtjd<dSr?)rBr;r@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)��2rErFrErFZTryingzthreads ...� )�end)rrc3s$|]}tjt����fd�VqdS))r4�argsN)r�Threadr!)�.0�i�rrrrrr �	<genexpr>s�
�zAThreadedImportTests.check_parallel_module_init.<locals>.<genexpr>iXz%.1f msg@�@T)�flushrHzdone: %s/%szOK.)�imp�	lock_held�unittestZSkipTestr�Eventr�printr;r@�KeyErrorr=r0�	monotonicr
�range�waitr�assertFalseZ
assertTrue)r.�mock_os�modname�t0Z	completedZdtZdbg_inforrMr �check_parallel_module_initks8
�


z.ThreadedImportTests.check_parallel_module_initcCs|��dSr:)r]r-rrr �test_parallel_module_init�sz-ThreadedImportTests.test_parallel_module_initc	CsRt�}tj�d|�z*|��|�|jd�|�|j	|j�W5tj�|�XdSr))
r(r;�	meta_path�insert�remover]�
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�)r5�ImportError)r3�rdrr �	path_hook�s
z?ThreadedImportTests.test_parallel_path_hooks.<locals>.path_hookrrf)r(r9r;�
path_hooksr`r_rrar5r]rbr*rcr)r.Zflushing_finderriZnumtestsrrhr �test_parallel_path_hooks�s
z,ThreadedImportTests.test_parallel_path_hookscCs<ztjd=Wntk
r YnXddl}|�|jj�dS)Nztest.threaded_import_hangersr)r;r@rUZtest.threaded_import_hangersrYZthreaded_import_hangersr)r.�testrrr �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$��resultsrr �	import_ab�sz<ThreadedImportTests.test_circular_imports.<locals>.import_abcsddl}��t|dd��dSrr)r%rrs)r%rtrr �	import_ba�sz<ThreadedImportTests.test_circular_imports.<locals>.import_ba)r4�a�b)�os�mkdirr�
addCleanup�shutilr	r;r3r`ra�circular_imports_modules�items�open�join�write�encoder�	importlib�invalidate_cachesrrJ�startrcr)	r.rnr2�contents�frvrw�t1�t2rrtr �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 = Nonerrorprq�__pycache__)r;r3r`rz�curdirr|rarr�r�r�rrr	r�r��
__import__r@)r.rZ�code�filenamer�rrr �test_side_effect_import�sz+ThreadedImportTests.test_side_effect_importN)
r6r7r8rCrDr#r]r^rerkrmr�r�rrrr r>_s
!

&r>c	CsVd}zt��}t�d�Wntk
r.YnXztt�W5|dk	rPt�|�XdS)Ng�h㈵��>)r;�getswitchinterval�setswitchinterval�AttributeErrorrr>)Zold_switchintervalrrr �	test_main�sr��__main__)�_imprPrzr�r;r0r}rrRrZtest.supportrrrrrrr	r
r!r#r~r(r9ZTestCaser>r�r6rrrr �<module>s0(
�