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: //usr/local/lib/python3.7/test/__pycache__/test_concurrent_futures.cpython-37.pyc
B

��g���@s�ddlZej�d�ej�d�ddlmZddlZddlZddlZddl	m
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlmZddlmZddlmZmZmZmZmZmZmZdd	lmZdd
l m!Z!ddl"Z eddfdd�Z#e#ed
�Z$e#ed
�Z%e#ed
�Z&e#ed
�Z'e#ee(�d�Z)e#edd�Z*da+dd�Z,dd�Z-dd�Z.dd�Z/dd�Z0dd�Z1dhdd�Z2Gd d!�d!e3�Z4Gd"d#�d#�Z5d$d%�Z6Gd&d'�d'ej7�Z8Gd(d)�d)�Z9Gd*d+�d+e9�Z:Gd,d-�d-e9�Z;Gd.d/�d/e9�Z<Gd0d1�d1e9�Z=e8fe:e;e=e<ffd2d3�Z>Gd4d5�d5e9�Z?Gd6d7�d7e9�Z@e>e?�e>e@�Gd8d9�d9�ZAGd:d;�d;e:eAe8�ZBGd<d=�d=eA�ZCe>eCe;e=e<fd>�Gd?d@�d@�ZDGdAdB�dBe:eDe8�ZEe>eDe;e=e<fd>�GdCdD�dD�ZFe>eF�GdEdF�dF�ZGGdGdH�dHe:eGe8�ZHGdIdJ�dJeG�ZIe>eIe;e=e<fd>�dKdL�ZJdidMdN�ZKdOdP�ZLdQdR�ZMdSdT�ZNGdUdV�dVe3�ZOGdWdX�dXe3�ZPGdYdZ�dZe3�ZQGd[d\�d\e3�ZRGd]d^�d^e3�ZSGd_d`�d`e3�ZTGdadb�db�ZUe>eUe;e=e<fd>�Gdcdd�dde8�ZVejjWdedf��ZXeYdgk�r�eX�dS)j�NZ_multiprocessingzmultiprocessing.synchronize)�assert_python_ok)�QueueHandler)�
PicklingError)�futures)�PENDING�RUNNING�	CANCELLED�CANCELLED_AND_NOTIFIED�FINISHED�Future�BrokenExecutor)�BrokenProcessPool)�get_contextcCst�}||_||_||_|S)N)r�_state�
_exceptionZ_result)�state�	exception�result�f�r�8/usr/local/lib/python3.7/test/test_concurrent_futures.py�
create_future s
r)r)rr�*)rr�
uninitializedcCs||S)Nr)�x�yrrr�mul2srcOs||fS)Nr)�args�kwargsrrr�capture5srcCst�|�td��dS)Nzthis is an exception)�time�sleep�	Exception)�trrr�sleep_and_raise8s
r$cCs t�|�t|�tj��dS)N)r r!�print�sys�stdout�flush)r#�msgrrr�sleep_and_print<s
r*cCs|adS)N)�INITIALIZER_STATUS)rrrr�initAsr,cCstS)N)r+rrrr�get_init_statusEsr-cCsF|dk	r0t�d�}|�t|��|�d�d|_t�d�td��dS)Nzconcurrent.futures�CRITICALFg�������?zerror in initializer)	�loggingZ	getLoggerZ
addHandlerrZsetLevelZ	propagater r!�
ValueError)�	log_queueZloggerrrr�	init_failHs


r2c@seZdZdd�ZdS)�MyObjectcCsdS)Nr)�selfrrr�	my_methodSszMyObject.my_methodN)�__name__�
__module__�__qualname__r5rrrrr3Rsr3c@seZdZdd�Zdd�ZdS)�
EventfulGCObjcCs|��|_dS)N)�Event�event)r4�mgrrrr�__init__XszEventfulGCObj.__init__cCs|j��dS)N)r;�set)r4rrr�__del__[szEventfulGCObj.__del__N)r6r7r8r=r?rrrrr9Wsr9cCst�S)N)r3)�_rrr�make_dummy_object_srAc@seZdZdd�Zdd�ZdS)�BaseTestCasecCstj��|_dS)N)�test�supportZthreading_setup�_thread_key)r4rrr�setUpdszBaseTestCase.setUpcCstj��tjj|j�dS)N)rCrD�
reap_childrenZthreading_cleanuprE)r4rrr�tearDowngs
zBaseTestCase.tearDownN)r6r7r8rFrHrrrrrBcsrBcs@eZdZdZiZ�fdd�Z�fdd�Zdd�Zdd	�Z�Z	S)
�
ExecutorMixin�csft���t��|_t|d�r@|jf|j|��d�|j	��|_
n|jfd|ji|j	��|_
|��dS)N�ctx)�max_workers�
mp_contextrL)�superrFr �	monotonic�t1�hasattr�
executor_type�worker_countr�executor_kwargs�executor�_prime_executor)r4)�	__class__rrrFps



zExecutorMixin.setUpcsV|jjdd�d|_t��|j}tjjr:td|dd�|�	|dd�t
���dS)NT)�waitz%.2fs� )�endi,z+synchronization issue: test lasted too long)rU�shutdownr rOrPrCrD�verboser%Z
assertLessrNrH)r4Zdt)rWrrrHszExecutorMixin.tearDowncCs
t|j�S)N)rrK)r4rrrr�szExecutorMixin.get_contextcs2�fdd�t�j�D�}x|D]}|��qWdS)Ncsg|]}�j�tjd��qS)g�������?)rU�submitr r!)�.0r@)r4rr�
<listcomp>�sz1ExecutorMixin._prime_executor.<locals>.<listcomp>)�rangerSr)r4rrr)r4rrV�s

zExecutorMixin._prime_executor)
r6r7r8rSrTrFrHrrV�
__classcell__rr)rWrrIlsrIc@seZdZejZdS)�ThreadPoolMixinN)r6r7r8r�ThreadPoolExecutorrRrrrrrb�srbcs&eZdZejZdZ�fdd�Z�ZS)�ProcessPoolForkMixin�forkcstjdkr|�d�t���S)N�win32zrequire unix system)r&�platform�skipTestrNr)r4)rWrrr�s

z ProcessPoolForkMixin.get_context)	r6r7r8r�ProcessPoolExecutorrRrKrrarr)rWrrd�srdc@seZdZejZdZdS)�ProcessPoolSpawnMixinZspawnN)r6r7r8rrirRrKrrrrrj�srjcs&eZdZejZdZ�fdd�Z�ZS)�ProcessPoolForkserverMixinZ
forkservercstjdkr|�d�t���S)Nrfzrequire unix system)r&rgrhrNr)r4)rWrrr�s

z&ProcessPoolForkserverMixin.get_context)	r6r7r8rrirRrKrrarr)rWrrk�srkcCsTdd�}xF|D]>}d||j�||j�f}t||f|f|i�}|t�|<qWdS)NcSs4|�d�r|dd�S|�d�r,|dd�S|SdS)N)ZMixinZTests���ZTest���)�endswith)�namerrr�strip_mixin�s


z*create_executor_tests.<locals>.strip_mixinz%s%sTest)r6�type�globals)Zmixin�bases�executor_mixinsrpZexero�clsrrr�create_executor_tests�s
rvcs(eZdZdZ�fdd�Zdd�Z�ZS)�InitializerMixin�cs dattdd�|_t���dS)Nr)�initialized)�initializer�initargs)r+�dictr,rTrNrF)r4)rWrrrF�s
zInitializerMixin.setUpcs:�fdd�t�j�D�}x|D]}��|��d�qWdS)Ncsg|]}�j�t��qSr)rUr]r-)r^r@)r4rrr_�sz5InitializerMixin.test_initializer.<locals>.<listcomp>ry)r`rS�assertEqualr)r4rrr)r4r�test_initializer�s

z!InitializerMixin.test_initializer)r6r7r8rSrFr~rarr)rWrrw�srwcs>eZdZdZ�fdd�Zdd�Zdd�Zejdd	��Z	�Z
S)
�FailingInitializerMixinrxcsZt|d�r4|��|_|j��|_tt|jfd�|_nd|_d|_ttd�|_t��	�dS)NrK)rzr{)rz)
rQrrMZQueuer1r|r2rTrNrF)r4)rWrrrF�s

zFailingInitializerMixin.setUpc
Cs�|�d���y|j�t�}Wntk
r0Yn X|�t��|��WdQRXt��}x0|jj	s�t��|dkr||�
d�t�d�qZW|�t��|j�t�WdQRXWdQRXdS)Nz ValueError: error in initializerrJzexecutor not broken after 5 s.g{�G�z�?)�_assert_loggedrUr]r-r�assertRaisesrr rOZ_broken�failr!)r4�futurerPrrrr~�s

z(FailingInitializerMixin.test_initializercCsdS)Nr)r4rrrrV�sz'FailingInitializerMixin._prime_executorc	#s�|jdk	rLdVg}yx|�|j�����qWWqptjk
rHYqpXn$|�dd��}dVWdQRX|j}|�t	�fdd�|D��|�dS)Nzconcurrent.futuresr.c3s|]}�|kVqdS)Nr)r^�line)r)rr�	<genexpr>sz9FailingInitializerMixin._assert_logged.<locals>.<genexpr>)
r1�appendZ
get_nowaitZ
getMessage�queueZEmptyZ
assertLogs�output�
assertTrue�any)r4r)r��cmr)r)rr�s
z&FailingInitializerMixin._assert_logged)r6r7r8rSrFr~rV�
contextlib�contextmanagerr�rarr)rWrr�s
rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ExecutorShutdownTestcCs$|j��|�t|jjtdd�dS)NrxrJ)rUr[r��RuntimeErrorr]�pow)r4rrr�test_run_after_shutdowns
z,ExecutorShutdownTest.test_run_after_shutdowncCsDtddj|jjt|dd�d��\}}}|�|�|�|��d�dS)Nz-caKif 1:
            from concurrent.futures import {executor_type}
            from time import sleep
            from test.test_concurrent_futures import sleep_and_print
            if __name__ == "__main__":
                context = '{context}'
                if context == "":
                    t = {executor_type}(5)
                else:
                    from multiprocessing import get_context
                    context = get_context(context)
                    t = {executor_type}(5, mp_context=context)
                t.submit(sleep_and_print, 1.0, "apple")
            rK�)rR�contextsapple)r�formatrRr6�getattr�assertFalser}�strip)r4�rc�out�errrrr�test_interpreter_shutdowns


z.ExecutorShutdownTest.test_interpreter_shutdowncCsJtddj|jjt|dd�d��\}}}|�d|���|�|��d�dS)Nz-ca�if 1:
            import atexit
            @atexit.register
            def run_last():
                try:
                    t.submit(id, None)
                except RuntimeError:
                    print("runtime-error")
                    raise
            from concurrent.futures import {executor_type}
            if __name__ == "__main__":
                context = '{context}'
                if not context:
                    t = {executor_type}(5)
                else:
                    from multiprocessing import get_context
                    context = get_context(context)
                    t = {executor_type}(5, mp_context=context)
                    t.submit(id, 42).result()
            rKr�)rRr�z)RuntimeError: cannot schedule new futuress
runtime-error)	rr�rRr6r��assertIn�decoder}r�)r4r�r�r�rrr�&test_submit_after_interpreter_shutdown5s

z;ExecutorShutdownTest.test_submit_after_interpreter_shutdowncs:�fdd�td�D�}�j��x|D]}|��q&WdS)Ncsg|]}�j�tjd��qS)g�������?)rUr]r r!)r^r@)r4rrr_Rsz=ExecutorShutdownTest.test_hang_issue12364.<locals>.<listcomp>�2)r`rUr[r)r4�fsrr)r4r�test_hang_issue12364Qs

z)ExecutorShutdownTest.test_hang_issue12364N)r6r7r8r�r�r�r�rrrrr�sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ThreadPoolShutdownTestcCsdS)Nr)r4rrrrVYsz&ThreadPoolShutdownTest._prime_executorcCsl|j�tdd�|j�tdd�|j�tdd�|�t|jj�d�|j��x|jjD]}|��qXWdS)N�rx����)rUr]rr}�len�_threadsr[�join)r4r#rrr�test_threads_terminate\s
z-ThreadPoolShutdownTest.test_threads_terminatecCsjtjdd��<}|}|�t|�ttdd���ddddddddddg
�WdQRXx|jD]}|��qVWdS)	NrJ)rLrl�r�rx�r)	rrcr}�list�map�absr`r�r�)r4�erUr#rrr�test_context_manager_shutdownes$z4ThreadPoolShutdownTest.test_context_manager_shutdowncCs@tjdd�}|�ttdd��|j}~x|D]}|��q,WdS)NrJ)rLrl)rrcr�r�r`r�r�)r4rU�threadsr#rrr�test_del_shutdownns
z(ThreadPoolShutdownTest.test_del_shutdowncCsPtjddd�}|�ttdd��|j}~x"|D]}|�|jd�|��q.WdS)NrJZSpecialPool)rLZthread_name_prefixrlz^SpecialPool_[0-4]$)	rrcr�r�r`r��assertRegexror�)r4rUr�r#rrr�test_thread_names_assignedws

z1ThreadPoolShutdownTest.test_thread_names_assignedcCsNtjdd�}|�ttdd��|j}~x"|D]}|�|jd�|��q,WdS)NrJ)rLrlzThreadPoolExecutor-\d+_[0-4]$)	rrcr�r�r`r�r�ror�)r4rUr�r#rrr�test_thread_names_default�s
z0ThreadPoolShutdownTest.test_thread_names_defaultN)	r6r7r8rVr�r�r�r�r�rrrrr�Xs			r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ProcessPoolShutdownTestcCsdS)Nr)r4rrrrV�sz'ProcessPoolShutdownTest._prime_executorcCst|j�tdd�|j�tdd�|j�tdd�|�t|jj�d�|jj}|j��x|��D]}|��q`WdS)Nr�rxr�r�r�r�rJ)	rUr]rr}r��
_processesr[�valuesr�)r4�	processes�prrr�test_processes_terminate�s
z0ProcessPoolShutdownTest.test_processes_terminatecCsntjdd��>}|j}|�t|�ttdd���ddddddddddg
�WdQRXx|��D]}|�	�qZWdS)	NrJ)rLrlr�r�rxr�r)
rrir�r}r�r�r�r`r�r�)r4r�r�r�rrrr��s$z5ProcessPoolShutdownTest.test_context_manager_shutdowncCsjtjdd�}t|�ttdd���|j}|j}|j}|j}~|�	�x|�
�D]}|�	�qNW|��dS)NrJ)rLrl)rrir�r�r�r`Z_queue_management_threadr�Z_call_queuer�r�Zjoin_thread)r4rUZqueue_management_threadr�Z
call_queuer�rrrr��sz)ProcessPoolShutdownTest.test_del_shutdownN)r6r7r8rVr�r�r�rrrrr��s	r�)rtc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�	WaitTestscCsd|j�tdd�}|j�tjd�}tjt||gtjd�\}}|�	t
|g�|�|�	t
t|g�|�dS)Nr�rxg�?)�return_when)rUr]rr r!rrX�CANCELLED_FUTURE�FIRST_COMPLETEDr}r>)r4�future1�future2�doneZnot_donerrr�test_first_completed�szWaitTests.test_first_completedcCsT|j�tjd�}tjtt|gtjd�\}}|�	t
ttg�|�|�	t
|g�|�dS)Ng�?)r�)rUr]r r!rrX�CANCELLED_AND_NOTIFIED_FUTURE�SUCCESSFUL_FUTUREr�r}r>)r4r��finished�pendingrrr�+test_first_completed_some_already_completed�s
z5WaitTests.test_first_completed_some_already_completedcCsr|j�tdd�}|j�td�}|j�tjd�}tj|||gtjd�\}}|�	t
||g�|�|�	t
|g�|�dS)Nrxr�g�?r�)r�)rUr]rr$r r!rrX�FIRST_EXCEPTIONr}r>)r4r�r�Zfuture3r�r�rrr�test_first_exception�szWaitTests.test_first_exceptioncCsl|j�tdd�}|j�tjd�}tjttt	||gtj
d�\}}|�ttt	|g�|�|�tt|g�|�dS)Nr�rg�?)r�)
rUr]�divmodr r!rrXr�r�r�r�r}r>)r4r�r�r�r�rrr�*test_first_exception_some_already_complete�sz4WaitTests.test_first_exception_some_already_completecCsP|j�tjd�}tjt|gtjd�\}}|�t	tg�|�|�t	|g�|�dS)Nrx)r�)
rUr]r r!rrX�EXCEPTION_FUTUREr�r}r>)r4r�r�r�rrr�'test_first_exception_one_already_failed�sz1WaitTests.test_first_exception_one_already_failedcCsj|j�tdd�}|j�tdd�}tjttt||gtj	d�\}}|�
tttt||g�|�|�
t�|�dS)Nrxrr�)r�)rUr]r�rrrXr�r�r��
ALL_COMPLETEDr}r>)r4r�r�r�r�rrr�test_all_completed�szWaitTests.test_all_completedcCsn|j�tdd�}|j�tjd�}tjttt	||gdtj
d�\}}|�tttt	|g�|�|�t|g�|�dS)Nr�r�rJ)�timeoutr�)
rUr]rr r!rrXr�r�r�r�r}r>)r4r�r�r�r�rrr�test_timeoutszWaitTests.test_timeoutN)
r6r7r8r�r�r�r�r�r�r�rrrrr��s
r�c@seZdZdd�ZdS)�ThreadPoolWaitTestsc	slt����fdd��t��}t�d�z4��fdd�td�D�}���tj|tj	d�Wdt�|�XdS)Ncs���dS)N)rXr)r;rr�future_func)sz@ThreadPoolWaitTests.test_pending_calls_race.<locals>.future_funcg���ư>csh|]}�j����qSr)rUr])r^�i)r�r4rr�	<setcomp>.sz>ThreadPoolWaitTests.test_pending_calls_race.<locals>.<setcomp>�d)r�)
�	threadingr:r&�getswitchinterval�setswitchintervalr`r>rrXr�)r4Zoldswitchintervalr�r)r;r�r4r�test_pending_calls_race%s
z+ThreadPoolWaitTests.test_pending_calls_raceN)r6r7r8r�rrrrr�#sr�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�AsCompletedTestscCsV|j�tdd�}|j�tdd�}tt�ttt||g��}|�	tttt||g�|�dS)Nrxr�r�r�)
rUr]rr>r�as_completedr�r�r�r})r4r�r��	completedrrr�test_no_timeout=sz AsCompletedTests.test_no_timeoutcCsv|j�tjd�}t�}y.x(tjttt	|gdd�D]}|�
|�q0WWntjk
rZYnX|�tttt	g�|�dS)Nrxr)r�)
rUr]r r!r>rr�r�r�r��add�TimeoutErrorr})r4r�Zcompleted_futuresr�rrr�test_zero_timeoutMs z"AsCompletedTests.test_zero_timeoutcCs@|j�tjd�}dd�t�t�|d��D�}|�t	|�d�dS)NrxcSsg|]}|�qSrr)r^rrrrr_fsz;AsCompletedTests.test_duplicate_futures.<locals>.<listcomp>r�r�)
rUr]r r!rr��	itertools�repeatr}r�)r4r�r�rrr�test_duplicate_futures`sz'AsCompletedTests.test_duplicate_futuresc	Cs�dd�td�D�}|�ttd��|�ttdd��|�tj��@x8tj|dd�D]&}|�	|�t
�|�}~|�|��qRWWdQRX|d�
d	�xFt�|�D]8}|�	|�t
�|�}~|�|��|r�|d�
d	�q�WdS)
NcSsg|]
}t��qSr)r)r^r@rrrr_mszGAsCompletedTests.test_free_reference_yielded_future.<locals>.<listcomp>�)rr)rrr)r�rC)r`r�rr	r
r�rr�r��remove�weakref�ref�assertIsNone�
set_result)r4�futures_listr��wrrrr�"test_free_reference_yielded_futurejs"



z3AsCompletedTests.test_free_reference_yielded_futurec	CsLttttg}|�tj��}ttj|dd��WdQRX|�	t
|j�d�dS)Nr)r�z2 (of 4) futures unfinished)r��PENDING_FUTURE�RUNNING_FUTUREr�r�rr�r�r�r}�strr)r4r�r�rrr�"test_correct_timeout_exception_msg�s
z3AsCompletedTests.test_correct_timeout_exception_msgN)r6r7r8r�r�r�r�r�rrrrr�;s

r�c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	j
jd
d��Zdd�Z
dd�ZdS)�ExecutorTestcCs$|j�tdd�}|�d|���dS)Nrxr��)rUr]r�r}r)r4r�rrr�test_submit�szExecutorTest.test_submitc	Cs�|jjtddd�}|�d|���|jjtdddd�}|�|��dddd�f�|jjtdd	�}|�|��d
ddif�|�t��|jjdd�WdQRXdS)
Nrxr�)r�r�r�)r4�fn)r�)r��argrr�)r�)rUr]rr}rrr��	TypeError)r4r�rrr�test_submit_keyword�sz ExecutorTest.test_submit_keywordc	Csx|�t|j�ttd�td���ttttd�td����|�t|jjttd�td�dd��ttttd�td����dS)N�
r�)�	chunksize)r}r�rUr�r�r`)r4rrr�test_map�szExecutorTest.test_mapcCsR|j�tddddgddddg�}|�|��d�|�|��d�|�t|j�dS)Nr�rxr�rrJ)rr�)rUr�r�r}�__next__r��ZeroDivisionError)r4r�rrr�test_map_exception�s zExecutorTest.test_map_exceptioncCslg}y2x,|jjtjdddgdd�D]}|�|�q"WWntjk
rLYnX|�d�|�ddg|�dS)Nrr�rJ)r�zexpected TimeoutError)	rUr�r r!r�rr�r�r})r4�resultsr�rrr�test_map_timeout�s
zExecutorTest.test_map_timeoutcCs(|j�tdg|jd�|j��dS)Nrxr�)rUr�r�rSr[)r4rrr�test_shutdown_race_issue12456�sz*ExecutorTest.test_shutdown_race_issue12456csNt�}t���t�|�fdd��}|j�|j�~�jdd�}|�	|d�dS)Ncs���S)N)r>)�obj)�my_object_collectedrr�<lambda>��z7ExecutorTest.test_no_stale_references.<locals>.<lambda>g@)r�z-Stale reference not collected within timeout.)
r3r�r:r�r�rUr]r5rXr�)r4Z	my_objectZmy_object_callbackZ	collectedr)rr�test_no_stale_references�sz%ExecutorTest.test_no_stale_referencesc
Cs6x0dD](}|�td��|j|d�WdQRXqWdS)N)r���z"max_workers must be greater than 0)rL)�assertRaisesRegexr0rR)r4Znumberrrr�test_max_workers_negative�s
z&ExecutorTest.test_max_workers_negativecCs8x2|j�ttd��D]}t�|�}~|�|��qWdS)Nr�)rUr�rAr`r�r�r�)r4rr�rrr�test_free_reference�s
z ExecutorTest.test_free_referenceN)r6r7r8r�r�r�rrrrCrDZcpython_onlyr
r
rrrrrr��s
	r�c@seZdZdd�Zdd�ZdS)�ThreadPoolExecutorTestcsDg��fdd�}|j�|td��|jjdd�|��td��dS)zTests verifying issue 11777.cs��|�dS)N)r�)�n)r�rr�record_finished�szRThreadPoolExecutorTest.test_map_submits_without_iteration.<locals>.record_finishedr�T)rXN)rUr�r`r[ZassertCountEqual)r4rr)r�r�"test_map_submits_without_iteration�s
z9ThreadPoolExecutorTest.test_map_submits_without_iterationcCs&|��}|�|jt��pdd�dS)Nr�rJ)rRr}Z_max_workers�os�	cpu_count)r4rUrrr�test_default_workers�sz+ThreadPoolExecutorTest.test_default_workersN)r6r7r8rrrrrrr�s
rc@sReZdZe�ejdkd�dd��Zdd�Zdd�Z	e
d	d
��Zdd�Zd
d�Z
dS)�ProcessPoolExecutorTestrfzWindows-only process limitc	Cs(|�td��tjdd�WdQRXdS)Nzmax_workers must be <= 61�>)rL)rr0rri)r4rrr�test_max_workers_too_large�sz2ProcessPoolExecutorTest.test_max_workers_too_largecCsd|j�tjd�g}tt|jj����}|��x|D]}|�	t
|j�q4W|�	t
|jjtdd�dS)Nr�rxr�)
rUr]r r!�next�iterr�r��	terminater�r
rr�)r4rr�Zfutrrr�test_killed_child�s
z)ProcessPoolExecutorTest.test_killed_childc	s��fdd�}ttttd�td���}��t�jjttd�td�dd��|���t�jjttd�td�dd��|���t�jjttd�td�dd��|���t|�dS)Ncs$t�jjttd�td�dd��dS)N�(r)r�)r�rUr�r�r`r)r4rr�bad_map	sz;ProcessPoolExecutorTest.test_map_chunksize.<locals>.bad_maprr�)r�r�)r�r�r�r`r}rUr�r0)r4rr�r)r4r�test_map_chunksizesz*ProcessPoolExecutorTest.test_map_chunksizecCstd��dS)N�{)r�)rurrr�_test_tracebacksz'ProcessPoolExecutorTest._test_tracebackc	Cs�|j�|j�}|�t��}|��WdQRX|j}|�t|�t	�|�
|jd�|j}|�t|�t
jj�|�d|j�tj���2}y|�Wn"t	k
r�tjt���YnXWdQRX|�d|���dS)N)r z&raise RuntimeError(123) # some comment)rUr]r!r�r"rrZassertIsrqr�r}r�	__cause__rZprocessZ_RemoteTracebackr��tbrCrD�captured_stderrr&�
excepthook�exc_info�getvalue)r4r�r��exc�cause�f1rrr�test_tracebacks z&ProcessPoolExecutorTest.test_tracebackcCsbt|j���}t|�}|j�t|�}|��|�|j	j
dd��d}tj�
�|��|��dS)Nr�)r�)rrKZManagerr9rUr]�idrr�r;rXrCrDZ
gc_collectr[r�)r4r<rr�rrr�test_ressources_gced_in_workers2s
z7ProcessPoolExecutorTest.test_ressources_gced_in_workersN)r6r7r8�unittestZ
skipUnlessr&rgrrr�classmethodr!r+r-rrrrr�srcCsddl}|��t_dS)Nr)�io�StringIOr&�stderr)r0rrr�hide_process_stderrJsr3cCs*|rt�|�ddl}|��|��dS)zInduces a segfault.rN)r r!�faulthandlerZdisableZ_sigsegv)�delayr4rrr�_crashOs

r6cCst�d�dS)z#Induces a sys exit with exitcode 1.r�N)r&�exitrrrr�_exitXsr8cCst�|��dS)z-Function that raises an Exception in process.N)r3)ZErrrrr�_raise_error]sr9cCst�|�S)z(Function that returns a instance of cls.)r3)rurrr�_return_instancecsr:c@seZdZdZdd�ZdS)�
CrashAtPicklez5Bad object that triggers a segfault at pickling time.cCs
t�dS)N)r6)r4rrr�
__reduce__kszCrashAtPickle.__reduce__N)r6r7r8�__doc__r<rrrrr;isr;c@seZdZdZdd�ZdS)�CrashAtUnpicklez7Bad object that triggers a segfault at unpickling time.cCstdfS)Nr)r6)r4rrrr<qszCrashAtUnpickle.__reduce__N)r6r7r8r=r<rrrrr>osr>c@seZdZdZdd�ZdS)�ExitAtPicklez9Bad object that triggers a process exit at pickling time.cCs
t�dS)N)r8)r4rrrr<wszExitAtPickle.__reduce__N)r6r7r8r=r<rrrrr?usr?c@seZdZdZdd�ZdS)�ExitAtUnpicklez;Bad object that triggers a process exit at unpickling time.cCstdfS)Nr)r8)r4rrrr<}szExitAtUnpickle.__reduce__N)r6r7r8r=r<rrrrr@{sr@c@seZdZdZdd�ZdS)�
ErrorAtPicklez3Bad object that triggers an error at pickling time.cCsddlm}|d��dS)Nr)rzError in pickle)�pickler)r4rrrrr<�szErrorAtPickle.__reduce__N)r6r7r8r=r<rrrrrA�srAc@seZdZdZdd�ZdS)�ErrorAtUnpicklez5Bad object that triggers an error at unpickling time.cCsddlm}t|ffS)Nr)�UnpicklingError)rBrDr9)r4rDrrrr<�szErrorAtUnpickle.__reduce__N)r6r7r8r=r<rrrrrC�srCc@s4eZdZdZedd��Zdd�Zdd�Zdd	�Zd
S)�ExecutorDeadlockTest�cCst�|�|S)N)r r!)rurr5rrr�	_sleep_id�s
zExecutorDeadlockTest._sleep_idc	Cs�ddl}ddlm}|dd��$}|j|d�|�d�|��}WdQRXx|j��D]}|��qTW|j	dd�t
d|��tjd�|�
d	|���dS)
Nr)�
TemporaryFilezw+)�mode)�fileT)rXz
Traceback:
 zExecutor deadlock:

)r4ZtempfilerHZdump_traceback�seek�readr�r�rr[r%r&�
__stderr__r�)r4rUr4rHrr#r�rrr�_fail_on_deadlock�s
z&ExecutorDeadlockTest._fail_on_deadlockcCsh|jjdd�tt�ftdftt�ftdftt�ftdftt�ftdft	dtdft
dtd	ftt
ft
d
fttftdfttftdfttftd
fttftdfttftdfg}x�|D]�\}}}}|�|���tj����|jdt|j�d�}|j|f|��}|�|��<y|j|jd�Wn"tjk
�r4|�|�YnXWdQRX|jdd�WdQRXWdQRXq�WdS)NT)rXzerror at task picklezexit at task unpicklezerror at task unpicklezcrash at task unpicklerz%crash during func execution on workerz$exit during func execution on workerz%error during func execution on workerz$crash during result pickle on workerz#exit during result pickle on workerz$error during result pickle on workerz.error during result unpickle in result_handlerz-exit during result unpickle in result_handlerrx)rLrM)r�)rUr[r,rArr@r
rCr>r6r8�
SystemExitr9r�r:r;r?ZsubTestrCrDr$rRrrKr]r�r�TIMEOUTrr�rN)r4Zcrash_cases�funcr�errorrorUZresrrr�
test_crash�sH


zExecutorDeadlockTest.test_crashc
Csp|jjdd�|jdt|j�d��D}||_|jtdd�}|jdd�|�t��|�	�WdQRXWdQRXdS)NT)rXrx)rLrMg�������?)r5)
rUr[rRrrKr]r6r�r
r)r4rUrrrr�test_shutdown_deadlock�sz+ExecutorDeadlockTest.test_shutdown_deadlockN)	r6r7r8rPr/rGrNrSrTrrrrrE�s
4rEc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%S)&�FutureTestscs:d��fdd�}t�}|�|�|�d�|�d��dS)Ncs|���dS)N)r)�callback_future)�callback_resultrrr��sz6FutureTests.test_done_callback_with_result.<locals>.fnrJ)r�add_done_callbackr�r})r4r�rr)rWr�test_done_callback_with_result�s

z*FutureTests.test_done_callback_with_resultcs@d��fdd�}t�}|�|�|�td��|�d�j�dS)Ncs|���dS)N)r)rV)�callback_exceptionrrr��sz9FutureTests.test_done_callback_with_exception.<locals>.fnrC)rC)rrX�
set_exceptionr"r}r)r4r�rr)rZr�!test_done_callback_with_exception�s
z-FutureTests.test_done_callback_with_exceptioncs<d��fdd�}t�}|�|�|�|���|���dS)Ncs|���dS)N)�	cancelled)rV)�
was_cancelledrrr�
sz6FutureTests.test_done_callback_with_cancel.<locals>.fn)rrXr��cancel)r4r�rr)r^r�test_done_callback_with_cancels
z*FutureTests.test_done_callback_with_cancelc	s�tj���n}d�d��fdd�}�fdd�}t�}|�|�|�|�|�d�|���|���|�d|���WdQRXdS)NFcsd�td��dS)NTzdoh!)r")rV)�raising_was_calledrr�
raising_fnsz9FutureTests.test_done_callback_raises.<locals>.raising_fncsd�dS)NTr)rV)�
fn_was_calledrrr�sz1FutureTests.test_done_callback_raises.<locals>.fnrJzException: doh!)	rCrDr$rrXr�r�r�r')r4r2rbr�rr)rcrar�test_done_callback_raisess




z%FutureTests.test_done_callback_raisescs:d��fdd�}t�}|�d�|�|�|�d��dS)Ncs|���dS)N)r)rV)rWrrr�+sz=FutureTests.test_done_callback_already_successful.<locals>.fnrJ)rr�rXr})r4r�rr)rWr�%test_done_callback_already_successful)s

z1FutureTests.test_done_callback_already_successfulcs@d��fdd�}t�}|�td��|�|�|�d�j�dS)Ncs|���dS)N)r)rV)rZrrr�6sz9FutureTests.test_done_callback_already_failed.<locals>.fnrC)rC)rr[r"rXr}r)r4r�rr)rZr�!test_done_callback_already_failed4s
z-FutureTests.test_done_callback_already_failedcs<d��fdd�}t�}|�|���|�|�|���dS)Ncs|���dS)N)r])rV)r^rrr�Asz<FutureTests.test_done_callback_already_cancelled.<locals>.fn)rr�r_rX)r4r�rr)r^r�$test_done_callback_already_cancelled?s
z0FutureTests.test_done_callback_already_cancelledc	Cs\tj���H}dd�}t�}|�d�|�|�|�d|���|�d|���WdQRXdS)NcSstd��dS)Nzdoh!)r")rVrrrrbLszKFutureTests.test_done_callback_raises_already_succeeded.<locals>.raising_fnrJzexception calling callback forzdoh!)rCrDr$rr�rXr�r')r4r2rbrrrr�+test_done_callback_raises_already_succeededJs

z7FutureTests.test_done_callback_raises_already_succeededcCsd|�tt�d�|�tt�d�|�tt�d�|�tt�d�|�tt�d�|�tt�d�dS)Nz%<Future at 0x[0-9a-f]+ state=pending>z%<Future at 0x[0-9a-f]+ state=running>z'<Future at 0x[0-9a-f]+ state=cancelled>z5<Future at 0x[0-9a-f]+ state=finished raised OSError>z3<Future at 0x[0-9a-f]+ state=finished returned int>)r��reprr�r�r�r�r�r�)r4rrr�	test_reprZs



zFutureTests.test_reprcCs�ttd�}ttd�}ttd�}ttd�}ttt�d�}ttdd�}|�|���|�	|j
t�|�|���|�	|j
t�|�|���|�	|j
t�|�|���|�	|j
t�|�|���|�	|j
t�|�|���|�	|j
t�dS)N)r)rrrJ)rr)rrrrr	r
�OSErrorr�r_r}rr�)r4r*�f2Zf3Zf4Zf5Zf6rrr�test_cancelks$



zFutureTests.test_cancelcCsX|�t���|�t���|�t���|�t���|�t���|�t���dS)N)	r�r�r]r�r�r�r�r�r�)r4rrr�test_cancelled�szFutureTests.test_cancelledcCsX|�t���|�t���|�t���|�t���|�t���|�t���dS)N)	r�r�r�r�r�r�r�r�r�)r4rrr�	test_done�szFutureTests.test_donecCsX|�t���|�t���|�t���|�t���|�t���|�t���dS)N)	r�r�Zrunningr�r�r�r�r�r�)r4rrr�test_running�szFutureTests.test_runningcCsz|jtjtjdd�|jtjtjdd�|jtjtjdd�|jtjtjdd�|jt	t
jdd�|�tjdd�d�dS)Nr)r�r)
r�rr�r�rr��CancelledErrorr�r�rkr�r}r�)r4rrr�test_result_with_timeout�sz$FutureTests.test_result_with_timeoutcsJ�fdd�}ttd��tj|d�}|��|��jdd�d�|��dS)Ncst�d���d�dS)Nr�r)r r!r�r)r*rr�notification�s
z:FutureTests.test_result_with_success.<locals>.notification)r)�targetrJ)r�r)rrr��Thread�startr}rr�)r4rsr#r)r*r�test_result_with_success�s
z$FutureTests.test_result_with_successcsJ�fdd�}ttd��tj|d�}|��|jtj�jdd�|�	�dS)Ncst�d����dS)Nr�)r r!r_r)r*rrrs�s
z9FutureTests.test_result_with_cancel.<locals>.notification)r)rtrJ)r�)
rrr�rurvr�rrqrr�)r4rsr#r)r*r�test_result_with_cancel�s
z#FutureTests.test_result_with_cancelcCs�|jtjtjdd�|jtjtjdd�|jtjtjdd�|jtjtjdd�|�	t
tjdd�t��|�
tjdd�d�dS)Nr)r�)r�rr�r�rr�rqr�r�r��
isinstancer�rkr}r�)r4rrr�test_exception_with_timeout�sz'FutureTests.test_exception_with_timeoutcsN�fdd�}ttd��tj|d�}|��|�t�jdd�t��|�	�dS)Nc	s8t�d��j�t�_t��_�j��WdQRXdS)Nr�)r r!Z
_conditionr
rrkrZ
notify_allr)r*rrrs�s

z=FutureTests.test_exception_with_success.<locals>.notification)r)rtrJ)r�)
rrr�rurvr�ryrrkr�)r4rsr#r)r*r�test_exception_with_success�s
z'FutureTests.test_exception_with_successN)r6r7r8rYr\r`rdrerfrgrhrjrmrnrorprrrwrxrzr{rrrrrU�s$
rUcCs,ztj�t�Wdtj��tj��XdS)N)rCrDZrun_unittestr6rG�multiprocessing�utilZ_cleanup_testsrrrr�	test_main�s
r~�__main__)N)N)ZZtest.supportrCrD�
import_moduleZtest.support.script_helperrr�r�r/Zlogging.handlersrrr�r&r�r r.r�rBrZ
concurrentrZconcurrent.futures._baserrrr	r
rrZconcurrent.futures.processr
r|rZmultiprocessing.utilrr�r�r�r�rkr�r�r+rrr$r*r,r-r2�objectr3r9rAZTestCaserBrIrbrdrjrkrvrwrr�r�r�r�r�r�r�rrr3r6r8r9r:r;r>r?r@rArCrErUZreap_threadsr~r6rrrr�<module>s�$





	*

;@7)
e
PUQ

	\
s