HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //proc/self/root/usr/local/lib/python3.7/test/__pycache__/test_threaded_import.cpython-37.opt-2.pyc
B

��g�#�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZmZdd�Zdd�Zdd	d
dd�ZGd
d�d�ZGdd�d�ZGdd�dej�Zedd��Zedkr�e�dS)�N)�mock)	�verbose�
import_module�run_unittest�TESTFN�reap_threads�forget�unlink�rmtree�
start_threadsc	
Cs�zvy>t|�dr"ddl}ddl}nddl}ddl}|�dd�}Wn2tk
rr}z|�|�d��Wdd}~XYnXWd|�t���t|�|k}|r�|�	�XdS)N�r��)
�len�modulefinder�randomZ	randrange�	Exception�append�with_traceback�	threading�	get_ident�set)	�N�done�
done_tasks�errorsrr�x�eZfinished�r�5/usr/local/lib/python3.7/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)�numcallsrrZLock�lock)�selfrrr�__init__GszFinder.__init__Nc	Cs>|j�|jd7_WdQRX|j}t�d�|d|_dS)Nr
g{�G�z�?)r)r(r�timeZsleep)r*�name�path�targetrrrr�	find_specLs

zFinder.find_spec)NN)�__name__�
__module__�__qualname__r+r0rrrrr'Csr'c@seZdZddd�ZdS)�FlushingFinderNcCstj��dS)N)�sys�path_importer_cache�clear)r*r-r.r/rrrr0[szFlushingFinder.find_spec)NN)r1r2r3r0rrrrr4Wsr4c@s\eZdZdd�Zdd�Zedd��Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zedd��ZdS)�ThreadedImportTestscCstj�dd�|_dS)Nr)r5�modules�pop�
old_random)r*rrr�setUpaszThreadedImportTests.setUpcCs|jdk	r|jtjd<dS)Nr)r;r5r9)r*rrr�tearDownds
zThreadedImportTests.tearDownc
st��rt�d��t���x�dD]�tr8td�ddd�x.dD]&}ytj	|=Wq>t
k
rbYq>Xq>Wg�g����t�
�}t����fdd	�t��D���WdQRX��d
�}t�
�|}tr�td|dd
dd�dt���f}|��|�|�||�tr td�q WdS)Nz"can't run when import lock is held)��2r>r?r>r?ZTryingzthreads ...� )�end)rrc3s$|]}tjt����fd�VqdS))r/�argsN)r�Threadr )�.0�i)rrrrrr�	<genexpr>szAThreadedImportTests.check_parallel_module_init.<locals>.<genexpr>iXz%.1f msg@�@T)�flushrAzdone: %s/%szOK.)�imp�	lock_held�unittestZSkipTestrZEventr�printr5r9�KeyErrorr7r,Z	monotonicr�range�waitr�assertFalseZ
assertTrue)r*�mock_os�modnameZt0Z	completedZdtZdbg_infor)rrrrr�check_parallel_module_initks6





z.ThreadedImportTests.check_parallel_module_initcCs|��dS)N)rR)r*rrr�test_parallel_module_init�sz-ThreadedImportTests.test_parallel_module_initc	CsRt�}tj�d|�z*|��|�|jd�|�|j|j�Wdtj�	|�XdS)Nr)
r'r5�	meta_path�insertrR�
assertGreaterr(�assertEqualr�remove)r*�finderrrr�test_parallel_meta_path�sz+ThreadedImportTests.test_parallel_meta_pathc	s�t��t�}�fdd�}tj�d|�tj�|�z4|�d�|��}|�	�j
d�|��j�j
�Wdtj�
|�tj�
|�XdS)Ncs��d�t�dS)N�)r0�ImportError)r.)rYrr�	path_hook�s
z?ThreadedImportTests.test_parallel_path_hooks.<locals>.path_hookrr[)r'r4r5�
path_hooksrUrTrr0rRrVr(rWrrX)r*Zflushing_finderr]Znumtestsr)rYr�test_parallel_path_hooks�s
z,ThreadedImportTests.test_parallel_path_hookscCs<ytjd=Wntk
r YnXddl}|�|jj�dS)Nztest.threaded_import_hangersr)r5r9rLZtest.threaded_import_hangersrOZthreaded_import_hangersr)r*Ztestrrr�test_import_hangers�sz'ThreadedImportTests.test_import_hangersc	
sd}t�t�|�tjt�tj�dt�|�tjj	t�x`t
��D]T\}}|d|i}ttj�
t|d�d��}|�|�d��WdQRX|�t|�qDWt��g��fdd�}�fd	d
�}tj|d�}tj|d�}|��|��|�
�|�
�|�t��dd
h�dS)Ng�?r�delayz.py�wbzutf-8csddl}��t|dd��dS)Nrr)r#r�getattr)r#)�resultsrr�	import_ab�sz<ThreadedImportTests.test_circular_imports.<locals>.import_abcsddl}��t|dd��dS)Nrr)r$rrc)r$)rdrr�	import_ba�sz<ThreadedImportTests.test_circular_imports.<locals>.import_ba)r/�a�b)�os�mkdirr�
addCleanup�shutilr
r5r.rUrX�circular_imports_modules�items�open�join�write�encoder�	importlib�invalidate_cachesrrC�startrWr)	r*rar-�contents�frerfZt1Zt2r)rdr�test_circular_imports�s*
z)ThreadedImportTests.test_circular_importsc	Cs�d}tj�dtj�|�tjjtj�td}t|d��}|�	|�
d��WdQRX|�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 = Nonerz.pyrbzutf-8�__pycache__)r5r.rUri�curdirrkrXrrorqrrr	rr
rsrt�
__import__r9)r*rP�code�filenamerwrrr�test_side_effect_import�s	z+ThreadedImportTests.test_side_effect_importN)
r1r2r3r<r=r"rRrSrZr_r`rxr~rrrrr8_s"

&r8c	CsVd}yt��}t�d�Wntk
r.YnXztt�Wd|dk	rPt�|�XdS)Ng�h㈵��>)r5�getswitchinterval�setswitchinterval�AttributeErrorrr8)Zold_switchintervalrrr�	test_main�sr��__main__)�_imprHrirsr5r,rlrrJrZtest.supportrrrrrrr	r
rr r"rmr'r4ZTestCaser8r�r1rrrr�<module>s,,