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.10/test/__pycache__/test_concurrent_futures.cpython-310.opt-1.pyc
o

�i���@s2ddlmZddlmZddlmZe�d�ddlmZddlmZddl	Z	ddl
Z
ddlZddlm
Z
ddlZddlZddlZddlZddlZddlZddlZddlZdd	lmZdd
lmZddlmZmZmZmZmZm Z m!Z!ddl"m#Z#m$Z$ddl%Z&ddl'Z&ddl&Z(ej)d
d
d�r�e�*d��eddfdd�Z+e+ed�Z,e+ed�Z-e+ed�Z.e+ed�Z/e+ee0�d�Z1e+edd�Z2da3dd�Z4dd�Z5dd�Z6dd�Z7dd �Z8d!d"�Z9dmd#d$�Z:Gd%d&�d&e;�Z<Gd'd(�d(�Z=d)d*�Z>Gd+d,�d,ej?�Z@Gd-d.�d.�ZAGd/d0�d0eA�ZBGd1d2�d2eA�ZCGd3d4�d4eA�ZDGd5d6�d6eA�ZEe@feBeCeEeDffd7d8�ZFGd9d:�d:eA�ZGGd;d<�d<eA�ZHeFeG�eFeH�Gd=d>�d>�ZIGd?d@�d@eBeIe@�ZJGdAdB�dBeI�ZKeFeKeCeEeDfdC�GdDdE�dE�ZLGdFdG�dGeBeLe@�ZMeFeLeCeEeDfdC�GdHdI�dI�ZNeFeN�GdJdK�dK�ZOGdLdM�dMeBeOe@�ZPGdNdO�dOeO�ZQeFeQeCeEeDfdC�dmdPdQ�ZRdRdS�ZSdTdU�ZTdVdW�ZUdXdY�ZVGdZd[�d[e;�ZWGd\d]�d]e;�ZXGd^d_�d_e;�ZYGd`da�dae;�ZZGdbdc�dce;�Z[Gddde�dee;�Z\Gdfdg�dg�Z]eFe]eCeEeDfdC�Gdhdi�die@�Z^djdk�Z_e`dlk�re�a�dSdS)n�)�support)�
import_helper)�threading_helper�_multiprocessing)�hashlib_helper)�assert_python_okN)�QueueHandler��
PicklingError)�futures)�PENDING�RUNNING�	CANCELLED�CANCELLED_AND_NOTIFIED�FINISHED�Future�BrokenExecutor)�BrokenProcessPool�_check_system_limitsT)�addressZmemoryz test too slow on ASAN/MSAN buildcCst�}||_||_||_|S�N)r�_state�
_exception�_result)�state�	exception�result�f�r�9/usr/local/lib/python3.10/test/test_concurrent_futures.py�
create_future*s
r �r�rr�*�rr�
uninitializedcCs||Srr)�x�yrrr�mul<�r(cOs||fSrr)�args�kwargsrrr�capture?r)r,cCst�|�td��)Nzthis is an exception)�time�sleep�	Exception)�trrr�sleep_and_raiseBs
r1cCs t�|�t|�tj��dSr)r-r.�print�sys�stdout�flush)r0�msgrrr�sleep_and_printFs
r7cCs|adSr��INITIALIZER_STATUS)r&rrr�initK�r:cCstSrr8rrrr�get_init_statusO�r<cCsB|durt�d�}|�t|��|�d�d|_t�d�td��)N�concurrent.futures�CRITICALF皙�����?zerror in initializer)	�logging�	getLogger�
addHandlerr�setLevel�	propagater-r.�
ValueError)�	log_queue�loggerrrr�	init_failRs


rIc@�eZdZdd�ZdS)�MyObjectcCsdSrr��selfrrr�	my_method]r=zMyObject.my_methodN)�__name__�
__module__�__qualname__rNrrrrrK\srKc@�eZdZdd�Zdd�ZdS)�
EventfulGCObjcCs|��|_dSr)�Event�event)rM�mgrrrr�__init__b�zEventfulGCObj.__init__cCs|j��dSr)rU�setrLrrr�__del__erXzEventfulGCObj.__del__N)rOrPrQrWrZrrrrrSa�rScCst�Sr)rK)�_rrr�make_dummy_objectisr]c@rR)�BaseTestCasecCst��|_dSr)r�threading_setup�_thread_keyrLrrr�setUpnrXzBaseTestCase.setUpcCst��tj|j�dSr)r�
reap_childrenr�threading_cleanupr`rLrrr�tearDownqszBaseTestCase.tearDownN)rOrPrQrardrrrrr^mr[r^cs8eZdZdZiZ�fdd�Z�fdd�Zdd�Z�ZS)�
ExecutorMixin�cs`t���t��|_t|d�r!|jd|j|��d�|j	��|_
dS|jdd|ji|j	��|_
dS)N�ctx��max_workers�
mp_contextrir)�superrar-�	monotonic�t1�hasattr�
executor_type�worker_count�get_context�executor_kwargs�executorrL��	__class__rrrazs


����zExecutorMixin.setUpcsT|jjdd�d|_t��|j}tjrtd|dd�|�|dd�t	��
�dS)NT��waitz%.2fs� )�endi,z+synchronization issue: test lasted too long)rs�shutdownr-rlrmr�verboser2Z
assertLessrkrd)rMZdtrtrrrd�szExecutorMixin.tearDowncCst�|j�Sr)�mprqrgrLrrrrq��zExecutorMixin.get_context)	rOrPrQrprrrardrq�
__classcell__rrrtrrevsrec@seZdZejZdS)�ThreadPoolMixinN)rOrPrQr�ThreadPoolExecutorrorrrrr�s
rc�&eZdZejZdZ�fdd�Z�ZS)�ProcessPoolForkMixin�forkc�Fzt�Wnty|�d�Ynwtjdkr|�d�t���S�N�.ProcessPoolExecutor unavailable on this system�win32zrequire unix system�r�NotImplementedError�skipTestr3�platformrkrqrLrtrrrq��
�


z ProcessPoolForkMixin.get_context�	rOrPrQr�ProcessPoolExecutorrorgrqr~rrrtrr���r�cr�)�ProcessPoolSpawnMixin�spawncs2zt�Wnty|�d�Ynwt���S)Nr�)rr�r�rkrqrLrtrrrq�s
�
z!ProcessPoolSpawnMixin.get_contextr�rrrtrr��r�r�cr�)�ProcessPoolForkserverMixin�
forkservercr�r�r�rLrtrrrq�r�z&ProcessPoolForkserverMixin.get_contextr�rrrtrr��r�r�cCsPdd�}|D]}d||j�||j�f}t||f|f|i�}|t�|<qdS)NcSs0|�d�r|dd�S|�d�r|dd�S|S)N)ZMixinZTests���ZTest���)�endswith)�namerrr�strip_mixin�s


z*create_executor_tests.<locals>.strip_mixinz%s%sTest)rO�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)r9�dictr:rrrkrarLrtrrra�s
�zInitializerMixin.setUpcs6�fdd�t�j�D�}|D]
}��|��d�qdS)Ncsg|]}�j�t��qSr)rs�submitr<��.0r\rLrr�
<listcomp>�s�z5InitializerMixin.test_initializer.<locals>.<listcomp>r�)�rangerp�assertEqualr)rMrrrrLr�test_initializer�s
��z!InitializerMixin.test_initializer)rOrPrQrprar�r~rrrtrr��sr�cs6eZdZdZ�fdd�Zdd�Zejdd��Z�Z	S)�FailingInitializerMixinr�csZt|d�r|��|_|j��|_tt|jfd�|_nd|_d|_ttd�|_t��	�dS)Nrgr�)r�)
rnrqrj�QueuerGr�rIrrrkrarLrtrrra�s


�zFailingInitializerMixin.setUpc	Cs|�d��uz|j�t�}Wn	tyYnw|�t��|��Wd�n1s,wYt��}|jj	sOt��|dkrF|�
d�t�d�|jj	r9|�t��|j�t�Wd�n1sewYWd�dSWd�dS1s}wYdS)Nz ValueError: error in initializerrfzexecutor not broken after 5 s.g{�G�z�?)�_assert_loggedrsr�r<r�assertRaisesrr-rl�_broken�failr.)rM�futurermrrrr��s*�
�

���"�z(FailingInitializerMixin.test_initializerc#s��|jdur"dVg}z	|�|j�����q
tjy!Ynw|�dd��}dVWd�n1s6wY|j}|�t	�fdd�|D��|�dS)NTr>r?c3s�|]}�|vVqdSrr)r��line�r6rr�	<genexpr>s�z9FailingInitializerMixin._assert_logged.<locals>.<genexpr>)
rG�append�
get_nowait�
getMessage�queue�EmptyZ
assertLogs�output�
assertTrue�any)rMr6r��cmrr�rr�s$�
����z&FailingInitializerMixin._assert_logged)
rOrPrQrprar��
contextlib�contextmanagerr�r~rrrtrr��sr�c@�DeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�ExecutorShutdownTestcCs$|j��|�t|jjtdd�dS)Nr�rf)rsrzr��RuntimeErrorr��powrLrrr�test_run_after_shutdown&s

�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")
            rg��ro�context�apple)r�formatrorO�getattr�assertFalser��strip�rM�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()
            rgr�r�z)RuntimeError: cannot schedule new futuress
runtime-error)	rr�rorOr��assertIn�decoder�r�r�rrr�&test_submit_after_interpreter_shutdownBs
�z;ExecutorShutdownTest.test_submit_after_interpreter_shutdowncs6�fdd�td�D�}�j��|D]}|��qdS)Nc�g|]
}�j�tjd��qS�r@�rsr�r-r.r�rLrrr�_�z=ExecutorShutdownTest.test_hang_issue12364.<locals>.<listcomp>�2)r�rsrzr)rM�fsrrrLr�test_hang_issue12364^s


�z)ExecutorShutdownTest.test_hang_issue12364cs��fdd�td�D�}�jjdd�dd�|D�}��t|�d�dd�|D�}|D]}�j|��d	|j��d
���|�	��q*��t|�d�dS)Ncr�r�r�r�rLrrr�fr�z<ExecutorShutdownTest.test_cancel_futures.<locals>.<listcomp>r�T)�cancel_futurescSsg|]}|��r|�qSr��	cancelled�r��futrrrr�k��cSsg|]}|��s|�qSrr�r�rrrr�qr�zfut._state=r�r)
r�rsrzZ
assertGreater�lenr��doner�assertIsNoner)rMr�r�Zothersr�rrLr�test_cancel_futuresdsz(ExecutorShutdownTest.test_cancel_futurescCsZ|jtjkrt�d��tddj|jjt|dd�d��\}}}|�	|�|�
|��d�dS)z�shutdown(wait=False) doesn't hang at exit with running futures.

        See https://github.com/python/cpython/issues/83386.
        z9Hangs, see https://github.com/python/cpython/issues/83386r�a�if True:
            from concurrent.futures import {executor_type}
            from test.test_concurrent_futures import sleep_and_print
            if __name__ == "__main__":
                if {context!r}: multiprocessing.set_start_method({context!r})
                t = {executor_type}(max_workers=3)
                t.submit(sleep_and_print, 1.0, "apple")
                t.shutdown(wait=False)
            rgNr�r�)rorr��unittest�SkipTestrr�rOr�r�r�r�r�rrr�test_hang_gh83386{s�
�

z&ExecutorShutdownTest.test_hang_gh83386c
Cs�ttd�s
t�d��dd�}i}t|dd�r|��|d<|jddd	i|��}|�t��	�t�tj
|�}z!t�d
�|�t���|j
dd�Wt�d
�t�tj
|�dSt�d
�t�tj
|�w)z�shutdown(wait=True) doesn't hang when a future was submitted and
        quickly canceled right before shutdown.

        See https://github.com/python/cpython/issues/94440.
        �alarmz1Tested platform does not support the alarm signalcS�td��)Nztimed out waiting for shutdown�r�)Z_signumZ_framerrr�timeout�r)z7ExecutorShutdownTest.test_hang_gh94440.<locals>.timeoutrgNrjri�rfTrvrr)rn�signalr�r�r�rqror��intr�SIGALRMr��cancelrz)rMr�r+rsZold_handlerrrr�test_hang_gh94440�s&
�


�z&ExecutorShutdownTest.test_hang_gh94440N)
rOrPrQr�r�r�r�r�r�r�rrrrr�%sr�c@r�)�ThreadPoolShutdownTestcCs|dd�}t�d�}td�D]	}|j�||�q
|�t|jj�d�td�D]}|��q%|j�	�|jjD]}|�
�q5dS)NcS�|��dSr��acquire��lockrrr�acquire_lock�r}zCThreadPoolShutdownTest.test_threads_terminate.<locals>.acquire_lockr�)�	threading�	Semaphorer�rsr�r�r��_threads�releaserz�join)rMr��sem�ir0rrr�test_threads_terminate�s



�z-ThreadPoolShutdownTest.test_threads_terminatec
Csjtjdd��}|}|�t|�ttdd���gd��Wd�n1s$wY|jD]}|��q,dS)Nrf�rir��
rf�r�r�r�rr�r�r�r	)	rr�r��list�map�absr�rr)rM�ersr0rrr�test_context_manager_shutdown�s��

�z4ThreadPoolShutdownTest.test_context_manager_shutdowncCs<tjdd�}|�ttdd��}|j}~|D]}|��qdS)Nrfrr�)rr�rrr�rr�rMrs�res�threadsr0rrr�test_del_shutdown�s
�z(ThreadPoolShutdownTest.test_del_shutdowncCsFtjdd�}|�ttdd��}|j}|jdd�|D]}|��qdS)Nrfrr�Frv)rr�rrr�rrzrrrrr�test_shutdown_no_wait�s
�z,ThreadPoolShutdownTest.test_shutdown_no_waitcCsTtjddd�}|�ttdd��|j}~t��|D]
}|�|j	d�|�
�qdS)NrfZSpecialPool)riZthread_name_prefixr�z^SpecialPool_[0-4]$�rr�rrr�rr�
gc_collect�assertRegexr�r�rMrsrr0rrr�test_thread_names_assigned�s�
�z1ThreadPoolShutdownTest.test_thread_names_assignedcCsRtjdd�}|�ttdd��|j}~t��|D]
}|�|j	d�|�
�qdS)Nrfrr�zThreadPoolExecutor-\d+_[0-4]$rrrrr�test_thread_names_default�s
�z0ThreadPoolShutdownTest.test_thread_names_defaultcCs.tdd�\}}}|�|�|�|��d�dS)Nr�a[if True:
            from concurrent.futures import ThreadPoolExecutor
            from test.test_concurrent_futures import sleep_and_print
            if __name__ == "__main__":
                t = ThreadPoolExecutor()
                t.submit(sleep_and_print, .1, "apple")
                t.shutdown(wait=False, cancel_futures=True)
            r�)rr�r�r�r�rrr�test_cancel_futures_wait_false�s

z5ThreadPoolShutdownTest.test_cancel_futures_wait_falseN)
rOrPrQrrrrrrrrrrrr��s	

r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ProcessPoolShutdownTestcCs�dd�}|��}|jdd�dkr|j}nd}|�d�}td�D]	}|j�||�q|�t|jj	�|�td�D]}|�
�q7|jj	}|j��|��D]}|�
�qKdS)NcSr�rr�r�rrrr�
r}zFProcessPoolShutdownTest.test_processes_terminate.<locals>.acquire_lockF��
allow_noner�r�r)rq�get_start_methodrprr�rsr�r�r��
_processesrrz�valuesr)rMr�rjZexpected_num_processesrr\�	processes�prrr�test_processes_terminates 



�z0ProcessPoolShutdownTest.test_processes_terminatec
Csttjd|��d��}|j}|�t|�ttdd���gd��Wd�n1s(wY|�	�D]}|�
�q1dS)Nrfrhr�r)rr�rqrr�r
rrr�r r)rMr
r!r"rrrr#s���
�z5ProcessPoolShutdownTest.test_context_manager_shutdowncCsptjd|��d�}|�ttdd��}|j}|j}|j}|j}~t	�
�|��|��D]}|��q+|�
�dS)Nrfrhr�)rr�rqrrr��_executor_manager_threadr�_call_queuerrrr �join_thread)rMrsr�executor_manager_threadr!�
call_queuer"rrrr-s�
z)ProcessPoolShutdownTest.test_del_shutdowncCsltjd|��d�}|�ttdd��}|j}|j}|j}|j	dd�|�
�|��D]}|�
�q)|��dS)Nrfrhr�Frv)
rr�rqrrr�rr%r$rzrr r&)rMrsrr!r(r'r"rrrrCs�
z-ProcessPoolShutdownTest.test_shutdown_no_waitN)rOrPrQr#rrrrrrrrs

r)r�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�	WaitTestscCsH|j�tjd�}tj||gtjd�\}}|�|h|�|�t�|�dS�N��?��return_when)	rsr�r-r.rrw�
ALL_COMPLETEDr�rY)rMr�r��not_donerrr�
test_20369as

�zWaitTests.test_20369cCsd|j�tdd�}|j�tjd�}tjt||gtjd�\}}|�	t
|g�|�|�	t
t|g�|�dS)N�r�r+r,)rsr�r(r-r.rrw�CANCELLED_FUTURE�FIRST_COMPLETEDr�rY)rM�future1�future2r�r/rrr�test_first_completedjs
�zWaitTests.test_first_completedcCsT|j�tjd�}tjtt|gtjd�\}}|�	t
ttg�|�|�	t
|g�|�dSr*)rsr�r-r.rrw�CANCELLED_AND_NOTIFIED_FUTURE�SUCCESSFUL_FUTUREr3r�rY�rMr4�finished�pendingrrr�+test_first_completed_some_already_completedus
�
�z5WaitTests.test_first_completed_some_already_completedcCsr|j�tdd�}|j�td�}|j�tjd�}tj|||gtjd�\}}|�	t
||g�|�|�	t
|g�|�dS)Nr�r1r+r�r,)rsr�r(r1r-r.rrw�FIRST_EXCEPTIONr�rY)rMr4r5Zfuture3r:r;rrr�test_first_exception�s
�zWaitTests.test_first_exceptioncCsl|j�tdd�}|j�tjd�}tjttt	||gtj
d�\}}|�ttt	|g�|�|�tt|g�|�dS)Nr1rr+r,)
rsr��divmodr-r.rrwr8r2r7r=r�rY�rMr4r5r: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,)
rsr�r-r.rrw�EXCEPTION_FUTUREr=r�rYr9rrr�'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�rr1r,)rsr�r?r(rrwr8r7rBr.r�rYr@rrr�test_all_completed�s(�
���zWaitTests.test_all_completedcCsn|j�tdd�}|j�tjd�}tjttt	||gdtj
d�\}}|�tttt	|g�|�|�t|g�|�dS)N��rf)r�r-)
rsr�r(r-r.rrwr7rBr8r.r�rYr@rrr�test_timeout�s&�
���zWaitTests.test_timeoutN)rOrPrQr0r6r<r>rArCrDrGrrrrr)`s	
r)c@rJ)�ThreadPoolWaitTestsc	stt����fdd��t��}t�d�z ��fdd�td�D�}���tj|tj	d�Wt�|�dSt�|�w)Ncs���dSrrvr)rUrr�future_func�r}z@ThreadPoolWaitTests.test_pending_calls_race.<locals>.future_funcg���ư>csh|]}�j����qSr)rsr�)r�r)rIrMrr�	<setcomp>�r�z>ThreadPoolWaitTests.test_pending_calls_race.<locals>.<setcomp>�dr,)
r�rTr3�getswitchinterval�setswitchintervalr�rYrrwr.)rMZoldswitchintervalr�r)rUrIrMr�test_pending_calls_race�s
z+ThreadPoolWaitTests.test_pending_calls_raceN)rOrPrQrNrrrrrH�srHc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�AsCompletedTestscCsV|j�tdd�}|j�tdd�}tt�ttt||g��}|�	tttt||g�|�dS)Nr�r1rFrE)
rsr�r(rYr�as_completedr7rBr8r�)rMr4r5�	completedrrr�test_no_timeout�s$�����z AsCompletedTests.test_no_timeoutcCsp|j�tjd�}t�}ztjttt	|gdd�D]}|�
|�qWn
tjy*Ynw|�tttt	g�|�dS)Nr�r�r�)
rsr�r-r.rYrrPr7rBr8�add�TimeoutErrorr�)rMr4Zcompleted_futuresr�rrr�test_zero_timeout�s,�
�����z"AsCompletedTests.test_zero_timeoutcCs@|j�tjd�}dd�t�t�|d��D�}|�t	|�d�dS)Nr�cSsg|]}|�qSrr)r�rrrrr�s�z;AsCompletedTests.test_duplicate_futures.<locals>.<listcomp>r�r�)
rsr�r-r.rrP�	itertools�repeatr�r�)rMr4rQrrr�test_duplicate_futures
s
�z'AsCompletedTests.test_duplicate_futurescCs�dd�td�D�}|�ttd��|�ttdd��|�tj��'tj|dd�D]}|�	|�t
�|�}~t�
�|�|��q(Wd�n1sJwY|d�d	�t�|�D] }|�	|�t
�|�}~t�
�|�|��|r{|d�d	�q[dS)
NcSsg|]}t��qSr)rr�rrrr�szGAsCompletedTests.test_free_reference_yielded_future.<locals>.<listcomp>�r!r#r$rrS�test)r�r�r rrr�rrUrP�remove�weakref�refrrr��
set_result)rM�futures_listr��wrrrr�"test_free_reference_yielded_futures.

��

��z3AsCompletedTests.test_free_reference_yielded_futurecCs`ttttg}|�tj��}ttj|dd��Wd�n1s wY|�	t
|j�d�dS)NrrSz2 (of 4) futures unfinished)r7�PENDING_FUTURE�RUNNING_FUTUREr8r�rrUr
rPr��strr)rMr`r�rrr�"test_correct_timeout_exception_msg-s��z3AsCompletedTests.test_correct_timeout_exception_msgN)rOrPrQrRrVrYrbrfrrrrrO�s
rOc@sZeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	j
d
d��Zdd�Zdd�Z
dS)�ExecutorTestcCs$|j�tdd�}|�d|���dS)Nr�rZ�)rsr�r�r�r�rMr�rrr�test_submit=szExecutorTest.test_submitcCs�|jjtddd�}|�d|���|jjtdddd�}|�|��dddd�f�|�t��|jjtdd	�Wd�n1s@wY|�t��|jjdd
�Wd�dS1s]wYdS)Nr�rZ)r'�r�r�)rM�fn)r�)rl�arg)rm)rsr�r(r�rr,r��	TypeErrorrirrr�test_submit_keywordAs�"�z ExecutorTest.test_submit_keywordc	Csx|�t|j�ttd�td���ttttd�td����|�t|jjttd�td�dd��ttttd�td����dS)N�
r���	chunksize)r�r
rsrr�r�rLrrr�test_mapKs��zExecutorTest.test_mapcCsJ|j�tgd�gd��}|�|��d�|�|��d�|�t|j�dS)N)r�r�r�r�)r�r�rrf)rr�)rsrr?r��__next__r��ZeroDivisionError)rMrrrr�test_map_exceptionTszExecutorTest.test_map_exceptioncCsdg}z|jjtjgd�dd�D]}|�|�qWn
tjy"Ynw|�d�|�ddg|�dS)N)rrrErfrSzexpected TimeoutError)	rsrr-r.r�rrUr�r�)rM�resultsrrrr�test_map_timeoutZs

���
zExecutorTest.test_map_timeoutcCs(|j�tdg|jd�|j��dS)Nr�r�)rsrrerprzrLrrr�test_shutdown_race_issue12456hsz*ExecutorTest.test_shutdown_race_issue12456csPt�}t���t�|�fdd��}|j�|j�~�jt	j
d�}|�|d�dS)Ncs���Sr)rY)�obj�Zmy_object_collectedrr�<lambda>vsz7ExecutorTest.test_no_stale_references.<locals>.<lambda>rSz-Stale reference not collected within timeout.)rKr�rTr]r^rsr�rNrwr�
SHORT_TIMEOUTr�)rMZ	my_objectZmy_object_callbackZ	collectedrr{r�test_no_stale_referencesos��z%ExecutorTest.test_no_stale_referencesc	CsFdD]}|�td��|j|d�Wd�n1swYqdS)N)r���z"max_workers must be greater than 0r)�assertRaisesRegexrFro)rMZnumberrrr�test_max_workers_negatives����z&ExecutorTest.test_max_workers_negativecCs<|j�ttd��D]}t�|�}~t��|�|��q	dS)Nrp)	rsrr]r�r]r^rrr�)rMrzrarrr�test_free_reference�s
�z ExecutorTest.test_free_referenceN)rOrPrQrjrorsrvrxryrZcpython_onlyr~r�r�rrrrrg:s
	
rgc@sNeZdZdd�Zdd�Zdd�Zdd�Ze�e	e
d	�d
�dd��Zd
d�ZdS)�ThreadPoolExecutorTestcsDg��fdd�}|j�|td��|jjdd�|��td��dS)zTests verifying issue 11777.cs��|�dSr)r�)�n�r:rr�record_finished�rXzRThreadPoolExecutorTest.test_map_submits_without_iteration.<locals>.record_finishedrpTrvN)rsrr�rzZassertCountEqual)rMr�rr�r�"test_map_submits_without_iteration�s
z9ThreadPoolExecutorTest.test_map_submits_without_iterationcCs0|��}tdt��pdd�}|�|j|�dS)N� r�r	)ro�min�os�	cpu_countr��_max_workers)rMrsZexpectedrrr�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	cSr�rr�r�rrrr��r}z<ThreadPoolExecutorTest.test_saturation.<locals>.acquire_lockr�Trv)ror�rr�r�r�r�r�rrrz)rMrsr�rrrrr�test_saturation�s


z&ThreadPoolExecutorTest.test_saturationcCs`|��}|�tdd���|�tdd���|�tdd���|�t|j�d�|jdd	�dS)
Nr1r�rErFr��r�Trv)ror�r(rr�r�rrz�rMrsrrr�test_idle_thread_reuse�sz-ThreadPoolExecutorTest.test_idle_thread_reuse�register_at_forkzneed os.register_at_forkc
s��fdd��t�d��5}|��|�td�D]!}tjdt�d�d��
}|�t�Wd�n1s2wYqWd�dS1sCwYdS)Ncs|��|�dSr�r�)�poolr�rrr��szEThreadPoolExecutorTest.test_hang_global_shutdown_lock.<locals>.submitr�r�r�)rj)rr�r�r�r�r|rq�tuple)rMr�r\�workersrr�r�test_hang_global_shutdown_lock�s���"�z5ThreadPoolExecutorTest.test_hang_global_shutdown_lockc
s�t���g���fdd�}|jdd��V}|j|dd�}z=t�|j|ddgd	d
���"}|�tj	��t
|�Wd�n1s?wYWd�n1sNwYW���n���w|��Wd�n1slwY|�
�ddg�dS)
NcsH��d|�d��z���W��d|�d��dS��d|�d��w)Nzident=z startedz stopped)r�rw��ident��logZ
stop_eventrr�
log_n_wait�s
*zRThreadPoolExecutorTest.test_executor_map_current_future_cancel.<locals>.log_n_waitr�r�firstr��second�thirdrrSzident='first' startedzident='first' stopped)r�rTror�r��closingrr�rrU�nextrYrZassertListEqual)rMr�r�r��genrr�r�'test_executor_map_current_future_cancel�s(�
����
�z>ThreadPoolExecutorTest.test_executor_map_current_future_cancelN)
rOrPrQr�r�r�r�r��
skipUnlessrnr�r�r�rrrrr��s



r�c@steZdZe�ejdkd�dd��Zdd�Zdd�Z	e
d	d
��Zdd�Ze
�d
�dd��Zdd�Zdd�Zdd�ZdS)�ProcessPoolExecutorTestr�zWindows-only process limitcCs>|�td��tjdd�Wd�dS1swYdS)Nzmax_workers must be <= 61�>r)r�rFrr�rLrrr�test_max_workers_too_large�s
�"�z2ProcessPoolExecutorTest.test_max_workers_too_largecCs`|j�tjd�g}tt|jj����}|��|D]	}|�	t
|j�q|�	t
|jjtdd�dS)Nr�r�rZ)
rsr�r-r.r��iterrr �	terminater�rrr�)rMrr"r�rrr�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�(rrq)r
rsrr�r�rrLrr�bad_map�s$z;ProcessPoolExecutorTest.test_map_chunksize.<locals>.bad_mapr�rErqr�)r
rr�r�r�rsr�rF)rMr�r^rrLr�test_map_chunksize�s���z*ProcessPoolExecutorTest.test_map_chunksizecCr�)N�{r��r�rrr�_test_tracebackr;z'ProcessPoolExecutorTest._test_tracebackc	Cs�|j�|j�}|�t��}|��Wd�n1swY|j}|�t|�t	�|�
|jd�|j}|�t|�t
jj�|�d|j�t���}z|�t	y]tjt���YnwWd�n1shwY|�d|���dS)N)r�z&raise RuntimeError(123) # some comment)rsr�r�r�r/rrZassertIsr�r�r�r*�	__cause__r�process�_RemoteTracebackr��tbr�captured_stderrr3�
excepthook�exc_info�getvalue)rMr�r��exc�cause�f1rrr�test_tracebacks*
�
���z&ProcessPoolExecutorTest.test_traceback�md5cCs^|����}t|�}|j�t|�}|��|�|jj	dd��d}t
��|��|�
�dS)Nr�rS)rq�ManagerrSrsr��idrr�rUrwrrrzr)rMrVrzr�rrr�test_ressources_gced_in_workerssz7ProcessPoolExecutorTest.test_ressources_gced_in_workerscCsj|j}|��}|�d�}d|j}t|�D]}|�|j�q|�t|j	�|j�t|�D]}|�
�q,dS)Nrr�)rsrqrr�r�r�r�r�r�rr)rMrsrjrZ	job_countr\rrrr�0s


�z'ProcessPoolExecutorTest.test_saturationcCsp|j}|��jdd�dkrt�d��|�tdd���|�tdd���|�td	d
���|�t	|j
�d�dS)NFrr��(Incompatible with the fork start method.r1r�rErFr�r�r�)rsrqrr�r�r�r(rr�r�rr�rrr�test_idle_process_reuse_one;s
z3ProcessPoolExecutorTest.test_idle_process_reuse_onecCs�|j}|��jdd�dkrt�d��|�tdd���|�tdd�|�tdd	���|�td
d�|�tdd
���|�tdd�|�t	|j
�d�|��dS)NFrr�r��rF�!����r�r�r�	r�)rsrqrr�r�r�r(rZassertLessEqualr�rrzr�rrr� test_idle_process_reuse_multipleEs
z8ProcessPoolExecutorTest.test_idle_process_reuse_multipleN)rOrPrQr�r�r3r�r�r�r��classmethodr�r�rZrequires_hashdigestr�r�r�r�rrrrr��s



r�cCs*|rt�|�ddl}|��|��dS)zInduces a segfault.rN)r-r.�faulthandler�disableZ_sigsegv)�delayr�rrr�_crashYs

r�cCst�d�dS)z#Induces a sys exit with exitcode 1.r�N)r3�exitrrrr�_exitbsr�cCs|��)z-Function that raises an Exception in process.r)�Errrrr�_raise_errorg�r�cCsddl}|��t_|��)z@Function that raises an Exception in process and ignores stderr.rN)�io�StringIOr3�stderr)r�r�rrr�_raise_error_ignore_stderrls
r�cCs|�S)z(Function that returns a instance of cls.rr�rrr�_return_instancesr�r�c@�eZdZdZdd�ZdS)�
CrashAtPicklez5Bad object that triggers a segfault at pickling time.cC�
t�dSr�r�rLrrr�
__reduce__z�
zCrashAtPickle.__reduce__N�rOrPrQ�__doc__r�rrrrr�x�r�c@r�)�CrashAtUnpicklez7Bad object that triggers a segfault at unpickling time.cC�tdfS�Nrr�rLrrrr��r)zCrashAtUnpickle.__reduce__Nr�rrrrr�~r�r�c@r�)�ExitAtPicklez9Bad object that triggers a process exit at pickling time.cCr�r�r�rLrrrr��r�zExitAtPickle.__reduce__Nr�rrrrr��r�r�c@r�)�ExitAtUnpicklez;Bad object that triggers a process exit at unpickling time.cCr�r�r�rLrrrr��r)zExitAtUnpickle.__reduce__Nr�rrrrr��r�r�c@r�)�
ErrorAtPicklez3Bad object that triggers an error at pickling time.cCsddlm}|d��)Nrr	zError in pickle)�pickler
)rMr
rrrr��szErrorAtPickle.__reduce__Nr�rrrrr��r�r�c@r�)�ErrorAtUnpicklez5Bad object that triggers an error at unpickling time.cCsddlm}t|ffS)Nr)�UnpicklingError)r�r�r�)rMr�rrrr��s
zErrorAtUnpickle.__reduce__Nr�rrrrr��r�r�c@s�eZdZejZdd�Zdd�dd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#S)$�ExecutorDeadlockTestcCs�ddl}ddlm}|dd��}|j|d�|�d�|��}Wd�n1s)wY|j��D]}|��q3|j	dd�t
d|��tjd�|�
d	|���dS)
Nr)�
TemporaryFilezw+)�mode)�fileTrvz
Traceback:
 zExecutor deadlock:

)r��tempfiler�Zdump_traceback�seek�readrr r�rzr2r3�
__stderr__r�)rMrsr�r�rr�r"rrr�_fail_on_deadlock�s

�
z&ExecutorDeadlockTest._fail_on_deadlockF��
ignore_stderrc	Gs�|jjdd�|jd|��d�}|j|g|�R�}|r t��}nt��}z0|�	|��!|�|j
|jd�Wd�n1s?wYWd�n1sNwYWntj
yc|�|�Ynw|jdd�dS)NTrvr�rhrS)rsrzrorqr�rr�r��nullcontextr�r�TIMEOUTrrUr�)rM�error�funcr�r*rsrr�rrr�_check_crash�s(�
�����z!ExecutorDeadlockTest._check_crashcC�|�ttt��dSr)r�r
r�r�rLrrr�test_error_at_task_pickle�sz.ExecutorDeadlockTest.test_error_at_task_picklecCr�r)r�rr�r�rLrrr�test_exit_at_task_unpickle��z/ExecutorDeadlockTest.test_exit_at_task_unpicklecCr�r)r�rr�r�rLrrr�test_error_at_task_unpickle�rz0ExecutorDeadlockTest.test_error_at_task_unpicklecCr�r)r�rr�r�rLrrr�test_crash_at_task_unpickle�rz0ExecutorDeadlockTest.test_crash_at_task_unpicklecC�|�tt�dSr)r�rr�rLrrr�%test_crash_during_func_exec_on_worker��z:ExecutorDeadlockTest.test_crash_during_func_exec_on_workercCrr)r��
SystemExitr�rLrrr�$test_exit_during_func_exec_on_worker�rz9ExecutorDeadlockTest.test_exit_during_func_exec_on_workercCs|�ttt�dSr)r�r�r�rLrrr�%test_error_during_func_exec_on_worker�sz:ExecutorDeadlockTest.test_error_during_func_exec_on_workercC�|�ttt�dSr)r�rr�r�rLrrr�)test_crash_during_result_pickle_on_worker��z>ExecutorDeadlockTest.test_crash_during_result_pickle_on_workercCr
r)r�rr�r�rLrrr�(test_exit_during_result_pickle_on_worker�rz=ExecutorDeadlockTest.test_exit_during_result_pickle_on_workercCr
r)r�r
r�r�rLrrr�)test_error_during_result_pickle_on_worker�rz>ExecutorDeadlockTest.test_error_during_result_pickle_on_workercCs|jtttdd�dS)NTr�)r�rr�r�rLrrr�3test_error_during_result_unpickle_in_result_handler�s
�zHExecutorDeadlockTest.test_error_during_result_unpickle_in_result_handlercCr
r)r�rr�r�rLrrr�2test_exit_during_result_unpickle_in_result_handler�rzGExecutorDeadlockTest.test_exit_during_result_unpickle_in_result_handlerc	Cs�|jjdd�|jd|��d��:}||_|jtdd�}|jdd�|�t��|��Wd�n1s5wYWd�dSWd�dS1sMwYdS)NTrvr�rhr@)r�)	rsrzrorqr�r�r�rr)rMrsrrrr�test_shutdown_deadlocks�
��"�z+ExecutorDeadlockTest.test_shutdown_deadlockc	Cs�|jjdd�|jd|��d��<}||_|�td���|j}|�tt��}|jdd�|�	t
��|��Wd�n1s@wYWd�n1sOwY|��dS)NTrvr�rhr#F)rsrzrorqr�r�rr$r�r�r
r)rMrsZexecutor_managerrrrr�test_shutdown_deadlock_pickles �
���z2ExecutorDeadlockTest.test_shutdown_deadlock_pickleN)rOrPrQrr}r�r�r�r�rrrrrr	rr
rrrrrrrrrr��s$r�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)Nc�|���dSr�r�Zcallback_future�Zcallback_resultrrrl3�z6FutureTests.test_done_callback_with_result.<locals>.fnrf)r�add_done_callbackr_r��rMrlrrrr�test_done_callback_with_result1�

z*FutureTests.test_done_callback_with_resultcs@d��fdd�}t�}|�|�|�td��|�d�j�dS)Ncrr�rr�Zcallback_exceptionrrrl>rz9FutureTests.test_done_callback_with_exception.<locals>.fnr[�r[)rr�
set_exceptionr/r�r*rrrr�!test_done_callback_with_exception<s
z-FutureTests.test_done_callback_with_exceptioncs<d��fdd�}t�}|�|�|�|���|���dS)Ncrrr�r�Z
was_cancelledrrrlIrz6FutureTests.test_done_callback_with_cancel.<locals>.fn)rrr�r�rrr"r�test_done_callback_with_cancelGs
z*FutureTests.test_done_callback_with_cancelcs�t���=}d�d��fdd�}�fdd�}t�}|�|�|�|�|�d�|���|���|�d|���Wd�dS1sDwYdS)NFcsd�td��)NT�doh!�r/r)�raising_was_calledrr�
raising_fnWsz9FutureTests.test_done_callback_raises.<locals>.raising_fncsd�dS)NTrr)�
fn_was_calledrrrl\r;z1FutureTests.test_done_callback_raises.<locals>.fnrfzException: doh!)rr�rrr_r�r�r�)rMr�r'rlrr)r(r&r�test_done_callback_raisesRs





"�z%FutureTests.test_done_callback_raisescs:d��fdd�}t�}|�d�|�|�|�d��dS)Ncrrrrrrrrljrz=FutureTests.test_done_callback_already_successful.<locals>.fnrf)rr_rr�rrrr�%test_done_callback_already_successfulhrz1FutureTests.test_done_callback_already_successfulcs@d��fdd�}t�}|�td��|�|�|�d�j�dS)Ncrrrrrrrrlurz9FutureTests.test_done_callback_already_failed.<locals>.fnr[r)rr r/rr�r*rrrr�!test_done_callback_already_failedss
z-FutureTests.test_done_callback_already_failedcs<d��fdd�}t�}|�|���|�|�|���dS)Ncrrr�rr"rrrl�rz<FutureTests.test_done_callback_already_cancelled.<locals>.fn)rr�r�rrrr"r�$test_done_callback_already_cancelled~s
z0FutureTests.test_done_callback_already_cancelledcCspt���*}dd�}t�}|�d�|�|�|�d|���|�d|���Wd�dS1s1wYdS)NcSr�)Nr$r%rrrrr'�r)zKFutureTests.test_done_callback_raises_already_succeeded.<locals>.raising_fnrfzexception calling callback forr$)rr�rr_rr�r�)rMr�r'rrrr�+test_done_callback_raises_already_succeeded�s


"�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�reprrcrdr2r7rBr8rLrrr�	test_repr�s(
�
�
�
���zFutureTests.test_reprcCs�ttd�}ttd�}ttd�}ttd�}ttt�d�}ttdd�}|�|���|�	|j
t�|�|���|�	|j
t�|�|���|�	|j
t�|�|���|�	|j
t�|�|���|�	|j
t�|�|���|�	|j
t�dS)Nr!r"rfr$)r rr
rrr�OSErrorr�r�r�rr�)rMr��f2Zf3Zf4Zf5Zf6rrr�test_cancel�s$



zFutureTests.test_cancelcCsX|�t���|�t���|�t���|�t���|�t���|�t���dSr)	r�rcr�rdr�r2r7rBr8rLrrr�test_cancelled��zFutureTests.test_cancelledcCsX|�t���|�t���|�t���|�t���|�t���|�t���dSr)	r�rcr�rdr�r2r7rBr8rLrrr�	test_done�r4zFutureTests.test_donecCsX|�t���|�t���|�t���|�t���|�t���|�t���dSr)	r�rc�runningr�rdr2r7rBr8rLrrr�test_running�r4zFutureTests.test_runningcCsz|jtjtjdd�|jtjtjdd�|jtjtjdd�|jtjtjdd�|jt	t
jdd�|�tjdd�d�dS)NrrSr#)
r�rrUrcrrd�CancelledErrorr2r7r0rBr�r8rLrrr�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>.notificationr!��targetrfrSr#)r rr��Thread�startr�rr�rMr;r0rr:r�test_result_with_success�s
z$FutureTests.test_result_with_successcsL�fdd�}ttd��tj|d�}|��|jtj�jt	j
d�|��dS)Ncst�d����dS�Nr�)r-r.r�rr:rrr;�s
z9FutureTests.test_result_with_cancel.<locals>.notificationr!r<rS)r rr�r>r?r�rr8rrr}rr@rr:r�test_result_with_cancel�s
�z#FutureTests.test_result_with_cancelcCs�|jtjtjdd�|jtjtjdd�|jtjtjdd�|jtjtjdd�|�	t
tjdd�t��|�
tjdd�d�dS)NrrS)r�rrUrcrrdr8r2r7r��
isinstancerBr0r�r8rLrrr�test_exception_with_timeouts �����z'FutureTests.test_exception_with_timeoutcsP�fdd�}ttd��tj|d�}|��|�t�jtj	d�t
��|��dS)NcsNt�d��j�t�_t��_�j��Wd�dS1s wYdSrB)r-r.�
_conditionrrr0r�
notify_allrr:rrr;s
"�z=FutureTests.test_exception_with_success.<locals>.notificationr!r<rS)r rr�r>r?r�rDrrr}r0rr@rr:r�test_exception_with_successs
z'FutureTests.test_exception_with_successcCsnttd�}|�d�|�tjd��
|�d�Wd�n1s!wY|�|���|�|�	�d�dS)Nr!r�z=FINISHED: <Future at 0x[0-9a-f]+ state=finished returned int>r�)
r rr_r�r�InvalidStateErrorr�r�r�r)rMrrrr�test_multiple_set_result"s

��z$FutureTests.test_multiple_set_resultcCshttd�}t�}|�|�|�tjd��|�t��Wd�n1s%wY|�|�	�|�dS)Nr!zBFINISHED: <Future at 0x[0-9a-f]+ state=finished raised ValueError>)
r rrFr r�rrIr/r�r)rMrr
rrr�test_multiple_set_exception0s

��z'FutureTests.test_multiple_set_exceptionN)rOrPrQrr!r#r)r*r+r,r-r/r2r3r5r7r9rArCrErHrJrKrrrrr0s*
rcCs.t�tjj�t��}tjtjg|�R�dSr)r�ZaddModuleCleanup�multiprocessing�util�_cleanup_testsrr_rc)�thread_inforrr�setUpModule?srP�__main__r)br[rZtest.supportrr�
import_modulerZtest.support.script_helperrr�rWrAZlogging.handlersrr�r�r�r3r�r-r�r]r�r
�
concurrentr�concurrent.futures._baserr
rrrrr�concurrent.futures.processrrZmultiprocessing.processrLZmultiprocessing.utilr|Zcheck_sanitizerr�r rcrdr2r7r0rBr8r9r(r,r1r7r:r<rI�objectrKrSr]ZTestCaser^rerr�r�r�r�r�r�r�r�rr)rHrOrgr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrPrO�mainrrrr�<module>s�
$






	!�
�8	^O��m��RVOu��
	
��
�