Your IP : 216.73.216.85


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_concurrent_futures.cpython-38.opt-1.pyc

U

i�f���@s�ddlZej�d�ej��ddlmZddlZddlZddl	Z	ddl
mZddlZddl
Z
ddlZddlZddlZddlZddlZddlmZddlmZddlmZmZmZmZmZmZmZddlm Z dd	l!m"Z"ddl#Z!ddl$Z!eddfd
d�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�Z0dd�Z1dd�Z2dd�Z3didd�Z4Gdd �d e5�Z6Gd!d"�d"�Z7d#d$�Z8Gd%d&�d&ej9�Z:Gd'd(�d(�Z;Gd)d*�d*e;�Z<Gd+d,�d,e;�Z=Gd-d.�d.e;�Z>Gd/d0�d0e;�Z?e:fe<e=e?e>ffd1d2�Z@Gd3d4�d4e;�ZAGd5d6�d6e;�ZBe@eA�e@eB�Gd7d8�d8�ZCGd9d:�d:e<eCe:�ZDGd;d<�d<eC�ZEe@eEe=e?e>fd=�Gd>d?�d?�ZFGd@dA�dAe<eFe:�ZGe@eFe=e?e>fd=�GdBdC�dC�ZHe@eH�GdDdE�dE�ZIGdFdG�dGe<eIe:�ZJGdHdI�dIeI�ZKe@eKe=e?e>fd=�dJdK�ZLdjdLdM�ZMdNdO�ZNdPdQ�ZOdRdS�ZPGdTdU�dUe5�ZQGdVdW�dWe5�ZRGdXdY�dYe5�ZSGdZd[�d[e5�ZTGd\d]�d]e5�ZUGd^d_�d_e5�ZVGd`da�da�ZWe@eWe=e?e>fd=�Gdbdc�dce:�ZXdaYddde�ZZdfdg�Z[e\dhk�r�e�]�dS)k�NZ_multiprocessing)�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�A/opt/alt/python38/lib64/python3.8/test/test_concurrent_futures.py�
create_future"s
r�r�rr�*�rr�
uninitializedcCs||Srr)�x�yrrr�mul4sr!cOs||fSrr)�args�kwargsrrr�capture7sr$cCst�|�td��dS)Nzthis is an exception)�time�sleep�	Exception)�trrr�sleep_and_raise:s
r)cCs t�|�t|�tj��dSr)r%r&�print�sys�stdout�flush)r(�msgrrr�sleep_and_print>s
r/cCs|adSr��INITIALIZER_STATUS)rrrr�initCsr2cCstSrr0rrrr�get_init_statusGsr3cCsF|dk	r0t�d�}|�t|��|�d�d|_t�d�td��dS)N�concurrent.futures�CRITICALF皙�����?zerror in initializer)	�loggingZ	getLoggerZ
addHandlerrZsetLevelZ	propagater%r&�
ValueError)�	log_queueZloggerrrr�	init_failJs


r:c@seZdZdd�ZdS)�MyObjectcCsdSrr��selfrrr�	my_methodUszMyObject.my_methodN)�__name__�
__module__�__qualname__r>rrrrr;Tsr;c@seZdZdd�Zdd�ZdS)�
EventfulGCObjcCs|��|_dSr)�Event�event)r=�mgrrrr�__init__ZszEventfulGCObj.__init__cCs|j��dSr)rD�setr<rrr�__del__]szEventfulGCObj.__del__N)r?r@rArFrHrrrrrBYsrBcCst�Sr)r;)�_rrr�make_dummy_objectasrJc@seZdZdd�Zdd�ZdS)�BaseTestCasecCstj��|_dSr)�test�support�threading_setup�_thread_keyr<rrr�setUpfszBaseTestCase.setUpcCstj��tjj|j�dSr)rLrMZ
reap_children�threading_cleanuprOr<rrr�tearDownis
zBaseTestCase.tearDownN)r?r@rArPrRrrrrrKesrKcs@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_contextrW)�superrPr%�	monotonic�t1�hasattr�
executor_type�worker_countr�executor_kwargs�executor�_prime_executorr<��	__class__rrrPrs


��
��zExecutorMixin.setUpcsV|jjdd�d|_t��|j}tjjr:td|dd�|�	|dd�t
���dS)NT��waitz%.2fs� )�endi,z+synchronization issue: test lasted too long)r`�shutdownr%rZr[rLrM�verboser*Z
assertLessrYrR)r=ZdtrbrrrR�szExecutorMixin.tearDowncCs
t|j�Sr)rrUr<rrrr�szExecutorMixin.get_contextcs.�fdd�t�j�D�}|D]}|��qdS)Ncsg|]}�j�tjd��qS�r6�r`�submitr%r&��.0rIr<rr�
<listcomp>�s�z1ExecutorMixin._prime_executor.<locals>.<listcomp>)�ranger^r�r=rrrr<rra�s

�zExecutorMixin._prime_executor)
r?r@rAr^r_rPrRrra�
__classcell__rrrbrrSnsrSc@seZdZejZdS)�ThreadPoolMixinN)r?r@rAr�ThreadPoolExecutorr]rrrrrs�srscs&eZdZejZdZ�fdd�Z�ZS)�ProcessPoolForkMixin�forkcstjdkr|�d�t���S�N�win32zrequire unix system�r+�platformZskipTestrYrr<rbrrr�s

z ProcessPoolForkMixin.get_context�	r?r@rAr�ProcessPoolExecutorr]rUrrrrrrbrru�sruc@seZdZejZdZdS)�ProcessPoolSpawnMixinZspawnN)r?r@rArr|r]rUrrrrr}�sr}cs&eZdZejZdZ�fdd�Z�ZS)�ProcessPoolForkserverMixinZ
forkservercstjdkr|�d�t���Srwryr<rbrrr�s

z&ProcessPoolForkserverMixin.get_contextr{rrrbrr~�sr~cCsPdd�}|D]>}d||j�||j�f}t||f|f|i�}|t�|<qdS)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)r?�type�globals)Zmixin�bases�executor_mixinsr�Zexer��clsrrr�create_executor_tests�s�r�cs(eZdZdZ�fdd�Zdd�Z�ZS)�InitializerMixin�cs dattdd�|_t���dS)Nr)�initialized��initializerZinitargs)r1�dictr2r_rYrPr<rbrrrP�s
�zInitializerMixin.setUpcs6�fdd�t�j�D�}|D]}��|��d�qdS)Ncsg|]}�j�t��qSr)r`rlr3rmr<rrro�s�z5InitializerMixin.test_initializer.<locals>.<listcomp>r�)rpr^�assertEqualrrqrr<r�test_initializer�s

�z!InitializerMixin.test_initializer)r?r@rAr^rPr�rrrrrbrr��sr�cs>eZdZdZ�fdd�Zdd�Zdd�Zejdd	��Z	�Z
S)
�FailingInitializerMixinr�csZt|d�r4|��|_|j��|_tt|jfd�|_nd|_d|_ttd�|_t��	�dS)NrUr�)r�)
r\rrXZQueuer9r�r:r_rYrPr<rbrrrP�s

�
zFailingInitializerMixin.setUpc
Cs�|�d���z|j�t�}Wntk
r0Yn X|�t��|��W5QRXt��}|jj	s�t��|dkrz|�
d�t�d�qX|�t��|j�t�W5QRXW5QRXdS)Nz ValueError: error in initializerrTzexecutor not broken after 5 s.g{�G�z�?)�_assert_loggedr`rlr3r
�assertRaisesrr%rZZ_broken�failr&)r=�futurer[rrrr��s
z(FailingInitializerMixin.test_initializercCsdSrrr<rrrrasz'FailingInitializerMixin._prime_executorc	#s�|jdk	rHdVg}z|�|j�����qWqltjk
rDYqlXn$|�dd��}dVW5QRX|j}|�t	�fdd�|D��|�dS)Nr4r5c3s|]}�|kVqdSrr)rn�line�r.rr�	<genexpr>sz9FailingInitializerMixin._assert_logged.<locals>.<genexpr>)
r9�appendZ
get_nowaitZ
getMessage�queueZEmptyZ
assertLogs�output�
assertTrue�any)r=r.r��cmrr�rr�s
�z&FailingInitializerMixin._assert_logged)r?r@rAr^rPr�ra�
contextlib�contextmanagerr�rrrrrbrr��sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ExecutorShutdownTestcCs$|j��|�t|jjtdd�dS)Nr�rT)r`rhr��RuntimeErrorrl�powr<rrr�test_run_after_shutdowns
�z,ExecutorShutdownTest.test_run_after_shutdowncCsDtddj|jjt|dd�d��\}}}|�|�|�|��d�dS)N�-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")
            rU��r]�contextsapple)r�formatr]r?�getattr�assertFalser��strip�r=Zrc�out�errrrr�test_interpreter_shutdown!s

�
z.ExecutorShutdownTest.test_interpreter_shutdowncCsJtddj|jjt|dd�d��\}}}|�d|���|�|��d�dS)Nr�a�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()
            rUr�r�z)RuntimeError: cannot schedule new futuress
runtime-error)	rr�r]r?r��assertIn�decoder�r�r�rrr�&test_submit_after_interpreter_shutdown7s
�z;ExecutorShutdownTest.test_submit_after_interpreter_shutdowncs6�fdd�td�D�}�j��|D]}|��q$dS)Ncsg|]}�j�tjd��qSrjrkrmr<rrroTsz=ExecutorShutdownTest.test_hang_issue12364.<locals>.<listcomp>�2)rpr`rhr)r=�fsrrr<r�test_hang_issue12364Ss
z)ExecutorShutdownTest.test_hang_issue12364N)r?r@rAr�r�r�r�rrrrr�sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ThreadPoolShutdownTestcCsdSrrr<rrrra[sz&ThreadPoolShutdownTest._prime_executorcCs|dd�}t�d�}td�D]}|j�||�q|�t|jj�d�td�D]}|��qJ|j�	�|jjD]}|�
�qjdS)NcSs|��dSr��acquire��lockrrr�acquire_lock_szCThreadPoolShutdownTest.test_threads_terminate.<locals>.acquire_lockr�)�	threading�	Semaphorerpr`rlr��len�_threads�releaserh�join)r=r��sem�ir(rrr�test_threads_terminate^s


z-ThreadPoolShutdownTest.test_threads_terminatecCsftjdd��<}|}|�t|�ttdd���ddddddddddg
�W5QRX|jD]}|��qTdS�	NrT�rWr�r�r��r)	rrtr��list�map�absrpr�r�)r=�er`r(rrr�test_context_manager_shutdownls�
z4ThreadPoolShutdownTest.test_context_manager_shutdowncCs<tjdd�}|�ttdd��|j}~|D]}|��q*dS�NrTr�r)rrtr�r�rpr�r��r=r`Zthreadsr(rrr�test_del_shutdownusz(ThreadPoolShutdownTest.test_del_shutdowncCsLtjddd�}|�ttdd��|j}~|D]}|�|jd�|��q,dS)NrTZSpecialPool)rWZthread_name_prefixrz^SpecialPool_[0-4]$�	rrtr�r�rpr��assertRegexr�r�r�rrr�test_thread_names_assigned~s�z1ThreadPoolShutdownTest.test_thread_names_assignedcCsJtjdd�}|�ttdd��|j}~|D]}|�|jd�|��q*dS)NrTr�rzThreadPoolExecutor-\d+_[0-4]$r�r�rrr�test_thread_names_default�sz0ThreadPoolShutdownTest.test_thread_names_defaultN)	r?r@rArar�r�r�r�r�rrrrr�Zs		r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ProcessPoolShutdownTestcCsdSrrr<rrrra�sz'ProcessPoolShutdownTest._prime_executorcCsp|j�tdd�|j�tdd�|j�tdd�|�t|jj�d�|jj}|j��|��D]}|��q^dS)N�r���r��rT)	r`rlr!r�r��
_processesrh�valuesr�)r=�	processes�prrr�test_processes_terminate�s
z0ProcessPoolShutdownTest.test_processes_terminatecCsjtjdd��>}|j}|�t|�ttdd���ddddddddddg
�W5QRX|��D]}|�	�qXdSr�)
rr|r�r�r�r�r�rpr�r�)r=r�r�r�rrrr��s�z5ProcessPoolShutdownTest.test_context_manager_shutdowncCsftjdd�}t|�ttdd���|j}|j}|j}|j}~|�	�|�
�D]}|�	�qL|��dSr�)rr|r�r�r�rpZ_queue_management_threadr�Z_call_queuer�r�Zjoin_thread)r=r`Zqueue_management_threadr�Z
call_queuer�rrrr��s
z)ProcessPoolShutdownTest.test_del_shutdownN)r?r@rArar�r�r�rrrrr��s	r�)r�c@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�r���?��return_when)r`rlr!r%r&rre�CANCELLED_FUTURE�FIRST_COMPLETEDr�rG)r=�future1�future2�doneZnot_donerrr�test_first_completed�s�
zWaitTests.test_first_completedcCsT|j�tjd�}tjtt|gtjd�\}}|�	t
ttg�|�|�	t
|g�|�dS)Nr�r�)r`rlr%r&rre�CANCELLED_AND_NOTIFIED_FUTURE�SUCCESSFUL_FUTUREr�r�rG�r=r��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)Nr�r�r�r�r�)r`rlr!r)r%r&rre�FIRST_EXCEPTIONr�rG)r=r�r�Zfuture3r�r�rrr�test_first_exception�s�
zWaitTests.test_first_exceptioncCsl|j�tdd�}|j�tjd�}tjttt	||gtj
d�\}}|�ttt	|g�|�|�tt|g�|�dS)Nr�rr�r�)
r`rl�divmodr%r&rrer�r�r�r�r�rG�r=r�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)Nr�r�)
r`rlr%r&rre�EXCEPTION_FUTUREr�r�rGr�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)Nr�rr�r�)r`rlr�r!rrer�r�r��
ALL_COMPLETEDr�rGr�rrr�test_all_completeds(��
��zWaitTests.test_all_completedcCsn|j�tdd�}|j�tjd�}tjttt	||gdtj
d�\}}|�tttt	|g�|�|�t|g�|�dS)Nr�r�rT)�timeoutr�)
r`rlr!r%r&rrer�r�r�r�r�rGr�rrr�test_timeouts(��
��zWaitTests.test_timeoutN)
r?r@rAr�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�W5t�|�XdS)Ncs���dSrrdr)rDrr�future_func0sz@ThreadPoolWaitTests.test_pending_calls_race.<locals>.future_funcg���ư>csh|]}�j����qSr)r`rl)rnr�)r�r=rr�	<setcomp>5sz>ThreadPoolWaitTests.test_pending_calls_race.<locals>.<setcomp>�dr�)
r�rCr+�getswitchinterval�setswitchintervalrprGrrer�)r=Zoldswitchintervalr�r)rDr�r=r�test_pending_calls_race,s
z+ThreadPoolWaitTests.test_pending_calls_raceN)r?r@rArrrrrr�*sr�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�AsCompletedTestscCsV|j�tdd�}|j�tdd�}tt�ttt||g��}|�	tttt||g�|�dS)Nr�r�r�r�)
r`rlr!rGr�as_completedr�r�r�r�)r=r�r��	completedrrr�test_no_timeoutDs(�����z AsCompletedTests.test_no_timeoutcCsr|j�tjd�}t�}z*tjttt	|gdd�D]}|�
|�q.Wntjk
rVYnX|�tttt	g�|�dS)Nr�r�r�)
r`rlr%r&rGrrr�r�r��add�TimeoutErrorr�)r=r�Zcompleted_futuresr�rrr�test_zero_timeoutTs(��
��z"AsCompletedTests.test_zero_timeoutcCs@|j�tjd�}dd�t�t�|d��D�}|�t	|�d�dS)Nr�cSsg|]}|�qSrr)rnrrrrrolsz;AsCompletedTests.test_duplicate_futures.<locals>.<listcomp>r�r�)
r`rlr%r&rr�	itertools�repeatr�r�)r=r�rrrr�test_duplicate_futuresgs
�z'AsCompletedTests.test_duplicate_futuresc	Cs�dd�td�D�}|�ttd��|�ttdd��|�tj��<tj|dd�D]&}|�	|�t
�|�}~|�|��qPW5QRX|d�
d	�t�|�D]8}|�	|�t
�|�}~|�|��|r�|d�
d	�q�dS)
NcSsg|]
}t��qSr)rrmrrrrotszGAsCompletedTests.test_free_reference_yielded_future.<locals>.<listcomp>�rrrrrrL)rpr�rr
rr�rr
r�remove�weakref�ref�assertIsNone�
set_result)r=�futures_listr��wrrrr�"test_free_reference_yielded_futureqs"



z3AsCompletedTests.test_free_reference_yielded_futurec	CsLttttg}|�tj��}ttj|dd��W5QRX|�	t
|j�d�dS)Nrrz2 (of 4) futures unfinished)r��PENDING_FUTURE�RUNNING_FUTUREr�r�rr
r�rr��strr)r=rr�rrr�"test_correct_timeout_exception_msg�s�z3AsCompletedTests.test_correct_timeout_exception_msgN)r?r@rArrrrrrrrrrBs

rc@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	j
jd
d��Zdd�Z
dd�ZdS)�ExecutorTestcCs$|j�tdd�}|�d|���dS)Nr�r�)r`rlr�r�r�r=r�rrr�test_submit�szExecutorTest.test_submitc	Cs�|jjtddd�}|�d|���|jjtdddd�}|�|��dddd�f�|�t��|jjtdd	�}W5QRX|�|��d
ddif�|�t	��|jjdd�W5QRXdS)
Nr�r)r �r�r�)r=�fn)r�)r!�argrr")r")
r`rlr!r�rr$ZassertWarns�DeprecationWarningr��	TypeErrorrrrr�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��Z	chunksize)r�r�r`r�r�rpr<rrr�test_map�s��zExecutorTest.test_mapcCsR|j�tddddgddddg�}|�|��d�|�|��d�|�t|j�dS)Nr�r�r�rrT)rr�)r`r�r�r��__next__r��ZeroDivisionError)r=r�rrr�test_map_exception�s zExecutorTest.test_map_exceptioncCshg}z.|jjtjdddgdd�D]}|�|�q Wntjk
rHYnX|�d�|�ddg|�dS)Nrr�rTrzexpected TimeoutError)	r`r�r%r&r�rr
r�r�)r=Zresultsr�rrr�test_map_timeout�s
�

zExecutorTest.test_map_timeoutcCs(|j�tdg|jd�|j��dS)Nr�r�)r`r�rr^rhr<rrr�test_shutdown_race_issue12456�sz*ExecutorTest.test_shutdown_race_issue12456csNt�}t���t�|�fdd��}|j�|j�~�jdd�}|�	|d�dS)Ncs���Sr)rG)�obj�Zmy_object_collectedrr�<lambda>��z7ExecutorTest.test_no_stale_references.<locals>.<lambda>g@rz-Stale reference not collected within timeout.)
r;r�rCrrr`rlr>rer�)r=Z	my_objectZmy_object_callbackZ	collectedrr/r�test_no_stale_references�s
��z%ExecutorTest.test_no_stale_referencesc
Cs2dD](}|�td��|j|d�W5QRXqdS)N)r���z"max_workers must be greater than 0r�)�assertRaisesRegexr8r])r=Znumberrrr�test_max_workers_negative�s
�z&ExecutorTest.test_max_workers_negativecCs4|j�ttd��D]}t�|�}~|�|��qdS)Nr&)r`r�rJrprrr)r=r.rrrr�test_free_reference�s
z ExecutorTest.test_free_referenceN)r?r@rArr%r(r+r,r-rLrMZcpython_onlyr2r5r6rrrrr�s	
rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ThreadPoolExecutorTestcsDg��fdd�}|j�|td��|jjdd�|��td��dS)zTests verifying issue 11777.cs��|�dSr)r�)�n�r�rr�record_finished�szRThreadPoolExecutorTest.test_map_submits_without_iteration.<locals>.record_finishedr&TrdN)r`r�rprhZassertCountEqual)r=r:rr9r�"test_map_submits_without_iteration�s
z9ThreadPoolExecutorTest.test_map_submits_without_iterationcCs0|��}tdt��pdd�}|�|j|�dS)N� r�r�)r]�min�os�	cpu_countr��_max_workers)r=r`Zexpectedrrr�test_default_workers�sz+ThreadPoolExecutorTest.test_default_workerscCs||�d�}dd�}t�d�}td|j�D]}|�||�q*|�t|j�|j�td|j�D]}|�	�q^|j
dd�dS)Nr�cSs|��dSrr�r�rrrr��sz<ThreadPoolExecutorTest.test_saturation.<locals>.acquire_lockr�Trd)r]r�r�rpr@rlr�r�r�r�rh)r=r`r�r�r�rrr�test_saturation�s


z&ThreadPoolExecutorTest.test_saturationcCs`|��}|�tdd���|�tdd���|�tdd���|�t|j�d�|jdd	�dS)
Nr�r�r�r�r�r�r�Trd)r]rlr!rr�r�r�rh)r=r`rrr�test_idle_thread_reusesz-ThreadPoolExecutorTest.test_idle_thread_reuseN)r?r@rAr;rArCrDrrrrr7�s

r7c@sReZdZe�ejdkd�dd��Zdd�Zdd�Z	e
d	d
��Zdd�Zd
d�Z
dS)�ProcessPoolExecutorTestrxzWindows-only process limitc	Cs(|�td��tjdd�W5QRXdS)Nzmax_workers must be <= 61�>r�)r4r8rr|r<rrr�test_max_workers_too_larges�z2ProcessPoolExecutorTest.test_max_workers_too_largecCs`|j�tjd�g}tt|jj����}|��|D]}|�	t
|j�q2|�	t
|jjtdd�dS)Nr�r�r)
r`rlr%r&�next�iterr�r��	terminater�rrr�)r=rr�Zfutrrr�test_killed_childs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�(r3r')r�r`r�r�rprr<rr�bad_map&sz;ProcessPoolExecutorTest.test_map_chunksize.<locals>.bad_maprLr�r'r�)r�r�r�rpr�r`r�r8)r=rMrrr<r�test_map_chunksize%s���z*ProcessPoolExecutorTest.test_map_chunksizecCstd��dS)N�{)r��r�rrr�_test_traceback5sz'ProcessPoolExecutorTest._test_tracebackc	Cs�|j�|j�}|�t��}|��W5QRX|j}|�t|�t	�|�
|jd�|j}|�t|�t
jj�|�d|j�tj���2}z|�Wn"t	k
r�tjt���YnXW5QRX|�d|���dS)N)rOz&raise RuntimeError(123) # some comment)r`rlrQr�r'rrZassertIsr�r�r�r"�	__cause__rZprocessZ_RemoteTracebackr��tbrLrM�captured_stderrr+�
excepthook�exc_info�getvalue)r=r�r��exc�cause�f1rrr�test_traceback9s"�z&ProcessPoolExecutorTest.test_tracebackcCsbt|j���}t|�}|j�t|�}|��|�|j	j
dd��d}tj�
�|��|��dS)Nr�r)rrUZManagerrBr`rl�idrr�rDrerLrMZ
gc_collectrhr�)r=rEr.r�rrr�test_ressources_gced_in_workersOs
z7ProcessPoolExecutorTest.test_ressources_gced_in_workersN)r?r@rA�unittestZ
skipUnlessr+rzrGrKrN�classmethodrQr[r]rrrrrEs

rEcCsddl}|��t_dS)Nr)�io�StringIOr+�stderr)r`rrr�hide_process_stderrgsrccCs*|rt�|�ddl}|��|��dS)zInduces a segfault.rN)r%r&�faulthandlerZdisableZ_sigsegv)�delayrdrrr�_crashls

rfcCst�d�dS)z#Induces a sys exit with exitcode 1.r�N)r+�exitrrrr�_exitusrhcCst�|��dS)z-Function that raises an Exception in process.N�rc)ZErrrrr�_raise_errorzsrjcCst�|�S)z(Function that returns a instance of cls.rirPrrr�_return_instance�srkc@seZdZdZdd�ZdS)�
CrashAtPicklez5Bad object that triggers a segfault at pickling time.cCs
t�dSr�rfr<rrr�
__reduce__�szCrashAtPickle.__reduce__N�r?r@rA�__doc__rnrrrrrl�srlc@seZdZdZdd�ZdS)�CrashAtUnpicklez7Bad object that triggers a segfault at unpickling time.cCstdfS�Nrrmr<rrrrn�szCrashAtUnpickle.__reduce__Nrorrrrrq�srqc@seZdZdZdd�ZdS)�ExitAtPicklez9Bad object that triggers a process exit at pickling time.cCs
t�dSr�rhr<rrrrn�szExitAtPickle.__reduce__Nrorrrrrs�srsc@seZdZdZdd�ZdS)�ExitAtUnpicklez;Bad object that triggers a process exit at unpickling time.cCstdfSrrrtr<rrrrn�szExitAtUnpickle.__reduce__Nrorrrrru�sruc@seZdZdZdd�ZdS)�
ErrorAtPicklez3Bad object that triggers an error at pickling time.cCsddlm}|d��dS)NrrzError in pickle)�pickler)r=rrrrrn�szErrorAtPickle.__reduce__Nrorrrrrv�srvc@seZdZdZdd�ZdS)�ErrorAtUnpicklez5Bad object that triggers an error at unpickling time.cCsddlm}t|ffS)Nr)�UnpicklingError)rwryrj)r=ryrrrrn�szErrorAtUnpickle.__reduce__Nrorrrrrx�srxc@s4eZdZdZedd��Zdd�Zdd�Zdd	�Zd
S)�ExecutorDeadlockTestrBcCst�|�|Sr)r%r&)r�rrerrr�	_sleep_id�s
zExecutorDeadlockTest._sleep_idc	Cs�ddl}ddlm}|dd��$}|j|d�|�d�|��}W5QRX|j��D]}|��qR|j	dd�t
d|��tjd�|�
d	|���dS)
Nr)�
TemporaryFilezw+)�mode)�fileTrdz
Traceback:
 zExecutor deadlock:

)rdZtempfiler|Zdump_traceback�seek�readr�r�rJrhr*r+�
__stderr__r�)r=r`rdr|rrSr�rrr�_fail_on_deadlock�s

z&ExecutorDeadlockTest._fail_on_deadlockcCsd|jjdd�tt�ftdftt�ftdftt�ftdftt�ftdft	dtdft
dtd	ftt
ft
d
fttftdfttftdfttftd
fttftdfttftdfg}|D]�\}}}}|�|���tj����|jdt|j�d�}|j|f|��}|�|��<z|j|jd�Wn"tjk
�r2|�|�YnXW5QRX|jdd�W5QRXW5QRXq�dS)NTrdzerror 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_handlerr�rVr)r`rhr\rvrrurrxrqrfrh�
SystemExitrjr�rkrlrsZsubTestrLrMrTr]rrUrlr�r�TIMEOUTrr
r�)r=Zcrash_cases�funcr"�errorr�r`�resrrr�
test_crash�sd
�
�
����������!�zExecutorDeadlockTest.test_crashc
Csp|jjdd�|jdt|j�d��D}||_|jtdd�}|jdd�|�t��|�	�W5QRXW5QRXdS)NTrdr�rVr6)re)
r`rhr]rrUrlrfr�rr)r=r`rrrr�test_shutdown_deadlock�s�z+ExecutorDeadlockTest.test_shutdown_deadlockN)	r?r@rAr�r_r{r�r�r�rrrrrz�s
4rzc@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%d&�Zd'd(�Zd)S)*�FutureTestscs:d��fdd�}t�}|�|�|�d�|�d��dS)Ncs|���dSr�r�Zcallback_future�Zcallback_resultrrr!sz6FutureTests.test_done_callback_with_result.<locals>.fnrT)r�add_done_callbackrr��r=r!rrr�r�test_done_callback_with_results

z*FutureTests.test_done_callback_with_resultcs@d��fdd�}t�}|�|�|�td��|�d�j�dS)Ncs|���dSr�rr��Zcallback_exceptionrrr!sz9FutureTests.test_done_callback_with_exception.<locals>.fnrL�rL)rr��
set_exceptionr'r�r"r�rr�r�!test_done_callback_with_exceptions
z-FutureTests.test_done_callback_with_exceptioncs<d��fdd�}t�}|�|�|�|���|���dS)Ncs|���dSr��	cancelledr��Z
was_cancelledrrr!'sz6FutureTests.test_done_callback_with_cancel.<locals>.fn)rr�r��cancelr�rr�r�test_done_callback_with_cancel%s
z*FutureTests.test_done_callback_with_cancelc	s�tj���n}d�d��fdd�}�fdd�}t�}|�|�|�|�|�d�|���|���|�d|���W5QRXdS)NFcsd�td��dS)NT�doh!�r'r�)�raising_was_calledrr�
raising_fn5sz9FutureTests.test_done_callback_raises.<locals>.raising_fncsd�dS)NTrr�)�
fn_was_calledrrr!:sz1FutureTests.test_done_callback_raises.<locals>.fnrTzException: doh!)	rLrMrTrr�rr�r�rW)r=rbr�r!rr)r�r�r�test_done_callback_raises0s




z%FutureTests.test_done_callback_raisescs:d��fdd�}t�}|�d�|�|�|�d��dS)Ncs|���dSrr�r�r�rrr!Hsz=FutureTests.test_done_callback_already_successful.<locals>.fnrT)rrr�r�r�rr�r�%test_done_callback_already_successfulFs

z1FutureTests.test_done_callback_already_successfulcs@d��fdd�}t�}|�td��|�|�|�d�j�dS)Ncs|���dSrr�r�r�rrr!Ssz9FutureTests.test_done_callback_already_failed.<locals>.fnrLr�)rr�r'r�r�r"r�rr�r�!test_done_callback_already_failedQs
z-FutureTests.test_done_callback_already_failedcs<d��fdd�}t�}|�|���|�|�|���dS)Ncs|���dSrr�r�r�rrr!^sz<FutureTests.test_done_callback_already_cancelled.<locals>.fn)rr�r�r�r�rr�r�$test_done_callback_already_cancelled\s
z0FutureTests.test_done_callback_already_cancelledc	Cs\tj���H}dd�}t�}|�d�|�|�|�d|���|�d|���W5QRXdS)NcSstd��dS)Nr�r�r�rrrr�iszKFutureTests.test_done_callback_raises_already_succeeded.<locals>.raising_fnrTzexception calling callback forr�)rLrMrTrrr�r�rW)r=rbr�rrrr�+test_done_callback_raises_already_succeededgs

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��reprrrr�r�r�r�r<rrr�	test_reprws(
�
�
�
���zFutureTests.test_reprcCs�ttd�}ttd�}ttd�}ttd�}ttt�d�}ttdd�}|�|���|�	|j
t�|�|���|�	|j
t�|�|���|�	|j
t�|�|���|�	|j
t�|�|���|�	|j
t�|�|���|�	|j
t�dS)NrrrTr)rrrr	r
r�OSErrorr�r�r�rr�)r=rZ�f2Zf3Zf4Zf5Zf6rrr�test_cancel�s$



zFutureTests.test_cancelcCsX|�t���|�t���|�t���|�t���|�t���|�t���dSr)	r�rr�rr�r�r�r�r�r<rrr�test_cancelled�szFutureTests.test_cancelledcCsX|�t���|�t���|�t���|�t���|�t���|�t���dSr)	r�rr�rr�r�r�r�r�r<rrr�	test_done�szFutureTests.test_donecCsX|�t���|�t���|�t���|�t���|�t���|�t���dSr)	r�rZrunningr�rr�r�r�r�r<rrr�test_running�szFutureTests.test_runningcCsz|jtjtjdd�|jtjtjdd�|jtjtjdd�|jtjtjdd�|jt	t
jdd�|�tjdd�d�dS)Nrrr)
r�rr
rrr�CancelledErrorr�r�r�r�r�r�r<rrr�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&rr�rZrr�notification�s
z:FutureTests.test_result_with_success.<locals>.notificationr��targetrTrr)rrr��Thread�startr�rr��r=r�r(rr�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�rr�rrr��s
z9FutureTests.test_result_with_cancel.<locals>.notificationrr�rTr)
rrr�r�r�r�rr�rr�r�rr�r�test_result_with_cancel�s
z#FutureTests.test_result_with_cancelcCs�|jtjtjdd�|jtjtjdd�|jtjtjdd�|jtjtjdd�|�	t
tjdd�t��|�
tjdd�d�dS)Nrr)r�rr
rrrr�r�r�r��
isinstancer�r�r�r�r<rrr�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��W5QRXdSr�)r%r&Z
_conditionrrr�rZ
notify_allrr�rrr��s

z=FutureTests.test_exception_with_success.<locals>.notificationrr�rTr)
rrr�r�r�r�r�rr�r�r�rr�r�test_exception_with_success�s
z'FutureTests.test_exception_with_successc	CsZttd�}|�d�|�tjd��|�d�W5QRX|�|���|�|�	�d�dS)Nrr�z=FINISHED: <Future at 0x[0-9a-f]+ state=finished returned int>r�)
rrrr4r�InvalidStateErrorr�r�r�r)r=rrrr�test_multiple_set_result�s

�z$FutureTests.test_multiple_set_resultc	CsTttd�}t�}|�|�|�tjd��|�t��W5QRX|�|�	�|�dS)NrzBFINISHED: <Future at 0x[0-9a-f]+ state=finished raised ValueError>)
rrr8r�r4rr�r'r�r)r=rr�rrr�test_multiple_set_exception
s

�z'FutureTests.test_multiple_set_exceptionN)r?r@rAr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s(
r�cCstj��adSr)rLrMrN�_threads_keyrrrr�setUpModulesr�cCstjjt�tj��dSr)rLrMrQr��multiprocessing�utilZ_cleanup_testsrrrr�tearDownModule#sr��__main__)N)N)^Ztest.supportrLrM�
import_moduleZ*skip_if_broken_multiprocessing_synchronizeZtest.support.script_helperrr�rr7Zlogging.handlersrr>r�r+r�r%r^rrwrZ
concurrentrZconcurrent.futures._baserrr	r
rrr
Zconcurrent.futures.processrr�rZmultiprocessing.processZmultiprocessing.utilrrrr�r�r�r�r�r1r!r$r)r/r2r3r:�objectr;rBrJZTestCaserKrSrsrur}r~r�r�r�r�r�r�r�r�rrr7rErcrfrhrjrkrlrqrsrurvrxrzr�r�r�r�r?�mainrrrr�<module>s�
$





	*

��
;@<)��e��PV&Q��
	\��