Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_concurrent_futures.cpython-38.pyc
U

>��g���@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�N�_multiprocessing)�assert_python_ok)�QueueHandler��
PicklingError)�futures)�PENDING�RUNNING�	CANCELLED�CANCELLED_AND_NOTIFIED�FINISHED�Future�BrokenExecutor)�BrokenProcessPool)�get_contextcCst�}||_||_||_|S�N)r
�_state�
_exception�_result)�state�	exception�result�f�r�;/opt/cppython/lib/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
r1cCs|adSr��INITIALIZER_STATUS)r!rrr�initCsr4cCstSrr2rrrr�get_init_statusGsr5cCsF|dk	r0t�d�}|�t|��|�d�d|_t�d�td��dS)N�concurrent.futures�CRITICALF皙�����?zerror in initializer)	�logging�	getLogger�
addHandlerr�setLevel�	propagater'r(�
ValueError)�	log_queue�loggerrrr�	init_failJs


rAc@seZdZdd�ZdS)�MyObjectcCsdSrr��selfrrr�	my_methodUszMyObject.my_methodN)�__name__�
__module__�__qualname__rErrrrrBTsrBc@seZdZdd�Zdd�ZdS)�
EventfulGCObjcCs|��|_dSr)�Event�event)rD�mgrrrr�__init__ZszEventfulGCObj.__init__cCs|j��dSr)rK�setrCrrr�__del__]szEventfulGCObj.__del__N)rFrGrHrMrOrrrrrIYsrIcCst�Sr)rB)�_rrr�make_dummy_objectasrQc@seZdZdd�Zdd�ZdS)�BaseTestCasecCstj��|_dSr)�test�support�threading_setup�_thread_keyrCrrr�setUpfszBaseTestCase.setUpcCstj��tjj|j�dSr)rSrT�
reap_children�threading_cleanuprVrCrrr�tearDownis
zBaseTestCase.tearDownN)rFrGrHrWrZrrrrrResrRcs@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_contextr_)�superrWr'�	monotonic�t1�hasattr�
executor_type�worker_countr�executor_kwargs�executor�_prime_executorrC��	__class__rrrWrs


��
��zExecutorMixin.setUpcsV|jjdd�d|_t��|j}tjjr:td|dd�|�	|dd�t
���dS)NT��waitz%.2fs� )�endi,z+synchronization issue: test lasted too long)rh�shutdownr'rbrcrSrT�verboser,Z
assertLessrarZ)rDZdtrjrrrZ�szExecutorMixin.tearDowncCs
t|j�Sr)rr]rCrrrr�szExecutorMixin.get_contextcs.�fdd�t�j�D�}|D]}|��qdS)Ncsg|]}�j�tjd��qS�r8�rh�submitr'r(��.0rPrCrr�
<listcomp>�s�z1ExecutorMixin._prime_executor.<locals>.<listcomp>)�rangerfr�rDrrrrCrri�s

�zExecutorMixin._prime_executor)
rFrGrHrfrgrWrZrri�
__classcell__rrrjrr[nsr[c@seZdZejZdS)�ThreadPoolMixinN)rFrGrHr�ThreadPoolExecutorrerrrrr{�sr{cs&eZdZejZdZ�fdd�Z�ZS)�ProcessPoolForkMixin�forkcstjdkr|�d�t���S�N�win32zrequire unix system�r-�platformZskipTestrarrCrjrrr�s

z ProcessPoolForkMixin.get_context�	rFrGrHr�ProcessPoolExecutorrer]rrzrrrjrr}�sr}c@seZdZejZdZdS)�ProcessPoolSpawnMixin�spawnN)rFrGrHrr�rer]rrrrr��sr�cs&eZdZejZdZ�fdd�Z�ZS)�ProcessPoolForkserverMixin�
forkservercstjdkr|�d�t���Srr�rCrjrrr�s

z&ProcessPoolForkserverMixin.get_contextr�rrrjrr��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)rF�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��initializer�initargs)r3�dictr4rgrarWrCrjrrrW�s
�zInitializerMixin.setUpcs6�fdd�t�j�D�}|D]}��|��d�qdS)Ncsg|]}�j�t��qSr)rhrtr5rurCrrrw�s�z5InitializerMixin.test_initializer.<locals>.<listcomp>r�)rxrf�assertEqualrryrrCr�test_initializer�s

�z!InitializerMixin.test_initializer)rFrGrHrfrWr�rzrrrjrr��sr�cs>eZdZdZ�fdd�Zdd�Zdd�Zejdd	��Z	�Z
S)
�FailingInitializerMixinr�csZt|d�r4|��|_|j��|_tt|jfd�|_nd|_d|_ttd�|_t��	�dS)Nr]r�)r�)
rdrr`�Queuer?r�rArgrarWrCrjrrrW�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 initializerr\zexecutor not broken after 5 s.g{�G�z�?)�_assert_loggedrhrtr5r�assertRaisesrr'rb�_broken�failr()rD�futurercrrrr��s
z(FailingInitializerMixin.test_initializercCsdSrrrCrrrrisz'FailingInitializerMixin._prime_executorc	#s�|jdk	rHdVg}z|�|j�����qWqltjk
rDYqlXn$|�dd��}dVW5QRX|j}|�t	�fdd�|D��|�dS)Nr6r7c3s|]}�|kVqdSrr)rv�line�r0rr�	<genexpr>sz9FailingInitializerMixin._assert_logged.<locals>.<genexpr>)
r?�append�
get_nowait�
getMessage�queue�EmptyZ
assertLogs�output�
assertTrue�any)rDr0r��cmrr�rr�s
�z&FailingInitializerMixin._assert_logged)rFrGrHrfrWr�ri�
contextlib�contextmanagerr�rzrrrjrr��sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ExecutorShutdownTestcCs$|j��|�t|jjtdd�dS)Nr�r\)rhrpr��RuntimeErrorrt�powrCrrr�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")
            r]��re�contextsapple)r�formatrerF�getattr�assertFalser��strip�rD�rc�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()
            r]r�r�z)RuntimeError: cannot schedule new futuress
runtime-error)	rr�rerFr��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��qSrrrsrurCrrrwTsz=ExecutorShutdownTest.test_hang_issue12364.<locals>.<listcomp>�2)rxrhrpr)rD�fsrrrCr�test_hang_issue12364Ss
z)ExecutorShutdownTest.test_hang_issue12364N)rFrGrHr�r�r�r�rrrrr�sr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ThreadPoolShutdownTestcCsdSrrrCrrrri[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�	Semaphorerxrhrtr��len�_threads�releaserp�join)rDr��sem�ir*rrr�test_threads_terminate^s


z-ThreadPoolShutdownTest.test_threads_terminatecCsftjdd��<}|}|�t|�ttdd���ddddddddddg
�W5QRX|jD]}|��qTdS�	Nr\�r_r��r�r��r)	rr|r��list�map�absrxr�r�)rD�erhr*rrr�test_context_manager_shutdownls�
z4ThreadPoolShutdownTest.test_context_manager_shutdowncCs<tjdd�}|�ttdd��|j}~|D]}|��q*dS�Nr\r�r�)rr|r�r�rxr�r��rDrh�threadsr*rrr�test_del_shutdownusz(ThreadPoolShutdownTest.test_del_shutdowncCsLtjddd�}|�ttdd��|j}~|D]}|�|jd�|��q,dS)Nr\ZSpecialPool)r_Zthread_name_prefixr�z^SpecialPool_[0-4]$�	rr|r�r�rxr��assertRegexr�r�r�rrr�test_thread_names_assigned~s�z1ThreadPoolShutdownTest.test_thread_names_assignedcCsJtjdd�}|�ttdd��|j}~|D]}|�|jd�|��q*dS)Nr\r�r�zThreadPoolExecutor-\d+_[0-4]$r�r�rrr�test_thread_names_default�sz0ThreadPoolShutdownTest.test_thread_names_defaultN)	rFrGrHrir�r�r�r�r�rrrrr�Zs		r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ProcessPoolShutdownTestcCsdSrrrCrrrri�sz'ProcessPoolShutdownTest._prime_executorcCsp|j�tdd�|j�tdd�|j�tdd�|�t|jj�d�|jj}|j��|��D]}|��q^dS)N�r���r��r\)	rhrtr#r�r��
_processesrp�valuesr�)rD�	processes�prrr�test_processes_terminate�s
z0ProcessPoolShutdownTest.test_processes_terminatecCsjtjdd��>}|j}|�t|�ttdd���ddddddddddg
�W5QRX|��D]}|�	�qXdSr�)
rr�r�r�r�r�r�rxr�r�)rDr�r�r�rrrr��s�z5ProcessPoolShutdownTest.test_context_manager_shutdowncCsftjdd�}t|�ttdd���|j}|j}|j}|j}~|�	�|�
�D]}|�	�qL|��dSr�)rr�r�r�r�rx�_queue_management_threadr��_call_queuer�r��join_thread)rDrhZqueue_management_threadr��
call_queuer�rrrr��s
z)ProcessPoolShutdownTest.test_del_shutdownN)rFrGrHrir�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)rhrtr#r'r(rrm�CANCELLED_FUTURE�FIRST_COMPLETEDr�rN)rD�future1�future2�done�not_donerrr�test_first_completed�s�
zWaitTests.test_first_completedcCsT|j�tjd�}tjtt|gtjd�\}}|�	t
ttg�|�|�	t
|g�|�dS)Nr�r�)rhrtr'r(rrm�CANCELLED_AND_NOTIFIED_FUTURE�SUCCESSFUL_FUTUREr�r�rN�rDr��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�)rhrtr#r+r'r(rrm�FIRST_EXCEPTIONr�rN)rDr�r�Zfuture3rrrrr�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�)
rhrt�divmodr'r(rrmrr�rr	r�rN�rDr�r�rrrrr�*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�)
rhrtr'r(rrm�EXCEPTION_FUTUREr	r�rNrrrr�'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�)rhrtrr#rrmrrr�
ALL_COMPLETEDr�rNrrrr�test_all_completeds(��
��zWaitTests.test_all_completedcCsn|j�tdd�}|j�tjd�}tjttt	||gdtj
d�\}}|�tttt	|g�|�|�t|g�|�dS)Nr�r�r\)�timeoutr�)
rhrtr#r'r(rrmrrrrr�rNrrrr�test_timeouts(��
��zWaitTests.test_timeoutN)
rFrGrHrrr
r
rrrrrrrr��s
r�c@seZdZdd�ZdS)�ThreadPoolWaitTestsc	slt����fdd��t��}t�d�z4��fdd�td�D�}���tj|tj	d�W5t�|�XdS)Ncs���dSrrlr)rKrr�future_func0sz@ThreadPoolWaitTests.test_pending_calls_race.<locals>.future_funcg���ư>csh|]}�j����qSr)rhrt)rvr�)rrDrr�	<setcomp>5sz>ThreadPoolWaitTests.test_pending_calls_race.<locals>.<setcomp>�dr�)
r�rJr-�getswitchinterval�setswitchintervalrxrNrrmr)rDZoldswitchintervalr�r)rKrrDr�test_pending_calls_race,s
z+ThreadPoolWaitTests.test_pending_calls_raceN)rFrGrHrrrrrr*src@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�AsCompletedTestscCsV|j�tdd�}|j�tdd�}tt�ttt||g��}|�	tttt||g�|�dS)Nr�r�r�r�)
rhrtr#rNr�as_completedrrrr�)rDr�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)
rhrtr'r(rNrrrrr�add�TimeoutErrorr�)rDr�Zcompleted_futuresr�rrr�test_zero_timeoutTs(��
��z"AsCompletedTests.test_zero_timeoutcCs@|j�tjd�}dd�t�t�|d��D�}|�t	|�d�dS)Nr�cSsg|]}|�qSrr)rvrrrrrwlsz;AsCompletedTests.test_duplicate_futures.<locals>.<listcomp>r�r�)
rhrtr'r(rr�	itertools�repeatr�r�)rDr�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
rurrrrwtszGAsCompletedTests.test_free_reference_yielded_future.<locals>.<listcomp>�rrrrrrS)rxr�rrrr�rr!r�remove�weakref�ref�assertIsNone�
set_result)rD�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_FUTURErr�rr!r�rr��strr)rDr,r�rrr�"test_correct_timeout_exception_msg�s�z3AsCompletedTests.test_correct_timeout_exception_msgN)rFrGrHrr"r%r.r2rrrrrBs

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&�)rhrtr�r�r�rDr�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�)rD�fn)r�)r8�argrr9)r9)
rhrtr#r�rr&ZassertWarns�DeprecationWarningr��	TypeErrorr5rrr�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�rhr�r�rxrCrrr�test_map�s��zExecutorTest.test_mapcCsR|j�tddddgddddg�}|�|��d�|�|��d�|�t|j�dS)Nr�r�r�rr\)rr�)rhr�rr��__next__r��ZeroDivisionError)rDr�rrr�test_map_exception�s zExecutorTest.test_map_exceptioncCshg}z.|jjtjdddgdd�D]}|�|�q Wntjk
rHYnX|�d�|�ddg|�dS)Nrr�r\rzexpected TimeoutError)	rhr�r'r(r�rr!r�r�)rD�resultsr�rrr�test_map_timeout�s
�

zExecutorTest.test_map_timeoutcCs(|j�tdg|jd�|j��dS)Nr�r�)rhr�r1rfrprCrrr�test_shutdown_race_issue12456�sz*ExecutorTest.test_shutdown_race_issue12456csNt�}t���t�|�fdd��}|j�|j�~�jdd�}|�	|d�dS)Ncs���Sr)rN)�obj�Zmy_object_collectedrr�<lambda>��z7ExecutorTest.test_no_stale_references.<locals>.<lambda>g@rz-Stale reference not collected within timeout.)
rBr�rJr(r)rhrtrErmr�)rDZ	my_objectZmy_object_callbackZ	collectedrrHr�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�)�assertRaisesRegexr>re)rDZnumberrrr�test_max_workers_negative�s
�z&ExecutorTest.test_max_workers_negativecCs4|j�ttd��D]}t�|�}~|�|��qdS)Nr=)rhr�rQrxr(r)r*)rDrGr-rrr�test_free_reference�s
z ExecutorTest.test_free_referenceN)rFrGrHr6r<r@rCrErFrSrTZcpython_onlyrKrNrOrrrrr3�s	
r3c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ThreadPoolExecutorTestcsDg��fdd�}|j�|td��|jjdd�|��td��dS)zTests verifying issue 11777.cs��|�dSr)r�)�n�rrr�record_finished�szRThreadPoolExecutorTest.test_map_submits_without_iteration.<locals>.record_finishedr=TrlN)rhr�rxrpZassertCountEqual)rDrSrrRr�"test_map_submits_without_iteration�s
z9ThreadPoolExecutorTest.test_map_submits_without_iterationcCs0|��}tdt��pdd�}|�|j|�dS)N� r�r�)re�min�os�	cpu_countr��_max_workers)rDrhZexpectedrrr�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�Trl)rer�r�rxrYrtr�r�r�r�rp)rDrhr�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�Trl)rertr#rr�r�r�rp)rDrhrrr�test_idle_thread_reusesz-ThreadPoolExecutorTest.test_idle_thread_reuseN)rFrGrHrTrZr\r]rrrrrP�s

rPc@sReZdZe�ejdkd�dd��Zdd�Zdd�Z	e
d	d
��Zdd�Zd
d�Z
dS)�ProcessPoolExecutorTestr�zWindows-only process limitc	Cs(|�td��tjdd�W5QRXdS)Nzmax_workers must be <= 61�>r�)rMr>rr�rCrrr�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&)
rhrtr'r(�next�iterr�r��	terminater�rrr�)rDrr�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�(rLr>)r�rhr�r�rxrrCrr�bad_map&sz;ProcessPoolExecutorTest.test_map_chunksize.<locals>.bad_maprer�r>r�)r�r�r�rxr�rhr�r>)rDrfr)rrCr�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)rhz&raise RuntimeError(123) # some comment)rhrtrjr�r)rrZassertIsr�r�r�r$�	__cause__r�process�_RemoteTracebackr��tbrSrT�captured_stderrr-�
excepthook�exc_info�getvalue)rDr�r��exc�cause�f1rrr�test_traceback9s"�z&ProcessPoolExecutorTest.test_tracebackcCsbt|j���}t|�}|j�t|�}|��|�|j	j
dd��d}tj�
�|��|��dS)Nr�r)rr]�ManagerrIrhrt�idrr�rKrmrSrT�
gc_collectrpr�)rDrLrGr�rrr�test_ressources_gced_in_workersOs
z7ProcessPoolExecutorTest.test_ressources_gced_in_workersN)rFrGrH�unittestZ
skipUnlessr-r�r`rdrg�classmethodrjrvrzrrrrr^s

r^cCsddl}|��t_dS)Nr)�io�StringIOr-�stderr)r}rrr�hide_process_stderrgsr�cCs*|rt�|�ddl}|��|��dS)zInduces a segfault.rN)r'r(�faulthandler�disableZ_sigsegv)�delayr�rrr�_crashls

r�cCst�d�dS)z#Induces a sys exit with exitcode 1.r�N)r-�exitrrrr�_exitusr�cCst�|��dS)z-Function that raises an Exception in process.N�r�)ZErrrrr�_raise_errorzsr�cCst�|�S)z(Function that returns a instance of cls.r�rirrr�_return_instance�sr�c@seZdZdZdd�ZdS)�
CrashAtPicklez5Bad object that triggers a segfault at pickling time.cCs
t�dSr�r�rCrrr�
__reduce__�szCrashAtPickle.__reduce__N�rFrGrH�__doc__r�rrrrr��sr�c@seZdZdZdd�ZdS)�CrashAtUnpicklez7Bad object that triggers a segfault at unpickling time.cCstdfS�Nrr�rCrrrr��szCrashAtUnpickle.__reduce__Nr�rrrrr��sr�c@seZdZdZdd�ZdS)�ExitAtPicklez9Bad object that triggers a process exit at pickling time.cCs
t�dSr�r�rCrrrr��szExitAtPickle.__reduce__Nr�rrrrr��sr�c@seZdZdZdd�ZdS)�ExitAtUnpicklez;Bad object that triggers a process exit at unpickling time.cCstdfSr�r�rCrrrr��szExitAtUnpickle.__reduce__Nr�rrrrr��sr�c@seZdZdZdd�ZdS)�
ErrorAtPicklez3Bad object that triggers an error at pickling time.cCsddlm}|d��dS)NrrzError in pickle)�pickler)rDrrrrr��szErrorAtPickle.__reduce__Nr�rrrrr��sr�c@seZdZdZdd�ZdS)�ErrorAtUnpicklez5Bad object that triggers an error at unpickling time.cCsddlm}t|ffS)Nr)�UnpicklingError)r�r�r�)rDr�rrrr��szErrorAtUnpickle.__reduce__Nr�rrrrr��sr�c@s4eZdZdZedd��Zdd�Zdd�Zdd	�Zd
S)�ExecutorDeadlockTestr[cCst�|�|Sr)r'r()r�r!r�rrr�	_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)�fileTrlz
Traceback:
 zExecutor deadlock:

)r��tempfiler�Zdump_traceback�seek�readr�r�rcrpr,r-�
__stderr__r�)rDrhr�r�rrnr�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)NTrlzerror 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�r^r)rhrprxr�rr�rr�r�r�r��
SystemExitr�r�r�r�r�ZsubTestrSrTrorerr]rtr�r�TIMEOUTrr!r�)rDZcrash_cases�funcr$�errorr�rh�resrrr�
test_crash�sd
�
�
����������!�zExecutorDeadlockTest.test_crashc
Csp|jjdd�|jdt|j�d��D}||_|jtdd�}|jdd�|�t��|�	�W5QRXW5QRXdS)NTrlr�r^r8)r�)
rhrprerr]rtr�r�rr)rDrhrrrr�test_shutdown_deadlock�s�z+ExecutorDeadlockTest.test_shutdown_deadlockN)	rFrGrHr�r|r�r�r�r�rrrrr��s
4r�c@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_resultrrr8sz6FutureTests.test_done_callback_with_result.<locals>.fnr\)r
�add_done_callbackr+r��rDr8rrr�r�test_done_callback_with_results

z*FutureTests.test_done_callback_with_resultcs@d��fdd�}t�}|�|�|�td��|�d�j�dS)Ncs|���dSr�rr��Zcallback_exceptionrrr8sz9FutureTests.test_done_callback_with_exception.<locals>.fnrS�rS)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_cancelledrrr8'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_calledrrr8:sz1FutureTests.test_done_callback_raises.<locals>.fnr\zException: doh!)	rSrTror
r�r+r�r�rr)rDrr�r8rr)r�r�r�test_done_callback_raises0s




z%FutureTests.test_done_callback_raisescs:d��fdd�}t�}|�d�|�|�|�d��dS)Ncs|���dSrr�r�r�rrr8Hsz=FutureTests.test_done_callback_already_successful.<locals>.fnr\)r
r+r�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�rrr8Ssz9FutureTests.test_done_callback_already_failed.<locals>.fnrSr�)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�rrr8^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_fnr\zexception calling callback forr�)rSrTror
r+r�r�rr)rDrr�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��reprr/r0r�rrrrCrrr�	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)Nrrr\r)rrr	r
rr�OSErrorr�r�r�rr�)rDru�f2Zf3Zf4Zf5Zf6rrr�test_cancel�s$



zFutureTests.test_cancelcCsX|�t���|�t���|�t���|�t���|�t���|�t���dSr)	r�r/r�r0r�r�rrrrCrrr�test_cancelled�szFutureTests.test_cancelledcCsX|�t���|�t���|�t���|�t���|�t���|�t���dSr)	r�r/rr0r�r�rrrrCrrr�	test_done�szFutureTests.test_donecCsX|�t���|�t���|�t���|�t���|�t���|�t���dSr)	r�r/�runningr�r0r�rrrrCrrr�test_running�szFutureTests.test_runningcCsz|jtjtjdd�|jtjtjdd�|jtjtjdd�|jtjtjdd�|jt	t
jdd�|�tjdd�d�dS)Nrrr)
r�rr!r/rr0�CancelledErrorr�rr�rr�rrCrrr�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�rurr�notification�s
z:FutureTests.test_result_with_success.<locals>.notificationr��targetr\rr)rrr��Thread�startr�rr��rDr�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�r\r)
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!r/rr0r�r�rr��
isinstancerr�r�rrCrrr�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(�
_conditionrrr�r�
notify_allrr�rrr��s

z=FutureTests.test_exception_with_success.<locals>.notificationrr�r\r)
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�)
rrr+rMr�InvalidStateErrorr�rr�r)rDrrrr�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>)
rrr>r�rMrr�r)r�r)rDrr�rrr�test_multiple_set_exception
s

�z'FutureTests.test_multiple_set_exceptionN)rFrGrHr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s(
r�cCstj��adSr)rSrTrU�_threads_keyrrrr�setUpModulesr�cCstjjt�tj��dSr)rSrTrYr��multiprocessing�util�_cleanup_testsrrrr�tearDownModule#sr��__main__)N)N)^Ztest.supportrSrT�
import_moduleZ*skip_if_broken_multiprocessing_synchronizeZtest.support.script_helperrr�r#r9Zlogging.handlersrrWr�r-r�r'r{r(r�rZ
concurrentr�concurrent.futures._baserr	r
rrr
rZconcurrent.futures.processrr�rZmultiprocessing.processZmultiprocessing.utilrr/r0r�rr�rrr3r#r&r+r1r4r5rA�objectrBrIrQZTestCaserRr[r{r}r�r�r�r�r�r�r�r�r�rrr3rPr^r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rF�mainrrrr�<module>s�
$





	*

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


F1le Man4ger