Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_concurrent_futures.cpython-35.pyc



��Yfe�@seddlZejjd�ejjd�ejjd�ddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZmZmZmZmZmZddlmZeddd	d
�Zede�Zede�Zede�Zede�Zedede��Zeded
d�Zdd�Zdd�Z dd�Z!Gdd�de"�Z#Gdd�d�Z$Gdd�de$�Z%Gdd�de$�Z&Gdd�d�Z'Gdd �d e%e'e
j(�Z)Gd!d"�d"e&e'e
j(�Z*Gd#d$�d$�Z+Gd%d&�d&e%e+e
j(�Z,Gd'd(�d(e&e+e
j(�Z-Gd)d*�d*�Z.Gd+d,�d,e%e.e
j(�Z/Gd-d.�d.e&e.e
j(�Z0Gd/d0�d0�Z1Gd1d2�d2e%e1e
j(�Z2Gd3d4�d4e&e1e
j(�Z3Gd5d6�d6e
j(�Z4ejj5d7d8��Z6e7d9krae6�dS):�NZ_multiprocessingzmultiprocessing.synchronize�	threading)�assert_python_ok)�futures)�PENDING�RUNNING�	CANCELLED�CANCELLED_AND_NOTIFIED�FINISHED�Future)�BrokenProcessPoolcCs(t�}||_||_||_|S)N)r
�_state�
_exceptionZ_result)�state�	exception�result�f�r�A/opt/alt/python35/lib64/python3.5/test/test_concurrent_futures.py�
create_futures
				rrrr�*cCs||S)Nr)�x�yrrr�mul+srcCstj|�td��dS)Nzthis is an exception)�time�sleep�	Exception)�trrr�sleep_and_raise/s
rcCs(tj|�t|�tjj�dS)N)rr�print�sys�stdout�flush)r�msgrrr�sleep_and_print3s

r#c@seZdZdd�ZdS)�MyObjectcCsdS)Nr)�selfrrr�	my_method:szMyObject.my_methodN)�__name__�
__module__�__qualname__r&rrrrr$9sr$c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�
ExecutorMixin�cCsttj�|_y|jd|j�|_Wn8tk
re}z|jt|��WYdd}~XnX|j�dS)N�max_workers)	r�t1�
executor_type�worker_count�executor�NotImplementedErrorZskipTest�str�_prime_executor)r%�errr�setUpAs&zExecutorMixin.setUpcCs]|jjdd�tj�|j}tjjrFtd|dd�|j|dd�dS)N�waitTz%.2fs�end� �<z+synchronization issue: test lasted too long)	r0�shutdownrr-�test�support�verboserZ
assertLess)r%Zdtrrr�tearDownIs
zExecutorMixin.tearDowncsA�fdd�t�j�D�}x|D]}|j�q)WdS)Ncs(g|]}�jjtjd��qS)g�������?)r0�submitrr)�.0�_)r%rr�
<listcomp>Ss	z1ExecutorMixin._prime_executor.<locals>.<listcomp>)�ranger/r)r%rrr)r%rr3Ps
zExecutorMixin._prime_executorN)r'r(r)r/r5r>r3rrrrr*>sr*c@seZdZejZdS)�ThreadPoolMixinN)r'r(r)r�ThreadPoolExecutorr.rrrrrDZsrDc@seZdZejZdS)�ProcessPoolMixinN)r'r(r)r�ProcessPoolExecutorr.rrrrrF^srFc@s4eZdZdd�Zdd�Zdd�ZdS)�ExecutorShutdownTestcCs0|jj�|jt|jjtdd�dS)N�r+)r0r:�assertRaises�RuntimeErrorr?�pow)r%rrr�test_run_after_shutdowncs
		z,ExecutorShutdownTest.test_run_after_shutdowncCsQtddjd|jj��\}}}|j|�|j|j�d�dS)Nz-caif 1:
            from concurrent.futures import {executor_type}
            from time import sleep
            from test.test_concurrent_futures import sleep_and_print
            t = {executor_type}(5)
            t.submit(sleep_and_print, 1.0, "apple")
            r.sapple)r�formatr.r'�assertFalse�assertEqual�strip)r%�rc�out�errrrr�test_interpreter_shutdownis$
z.ExecutorShutdownTest.test_interpreter_shutdowncsK�fdd�td�D�}�jj�x|D]}|j�q3WdS)Ncs(g|]}�jjtjd��qS)g�������?)r0r?rr)r@rA)r%rrrBxs	z=ExecutorShutdownTest.test_hang_issue12364.<locals>.<listcomp>�2)rCr0r:r)r%�fsrr)r%r�test_hang_issue12364ws

z)ExecutorShutdownTest.test_hang_issue12364N)r'r(r)rMrUrXrrrrrHbsrHc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ThreadPoolShutdownTestcCsdS)Nr)r%rrrr3sz&ThreadPoolShutdownTest._prime_executorcCs�|jjtdd�|jjtdd�|jjtdd�|jt|jj�d�|jj�x|jjD]}|j�qxWdS)N�rI����)r0r?rrP�len�_threadsr:�join)r%rrrr�test_threads_terminate�s
z-ThreadPoolShutdownTest.test_threads_terminatecCs�tjdd��V}|}|jt|jttdd���ddddddddddg
�WdQRXx|jD]}|j�quWdS)	Nr,r+�r]rI�r���)	rrErP�list�map�absrCr`ra)r%r4r0rrrr�test_context_manager_shutdown�s$,z4ThreadPoolShutdownTest.test_context_manager_shutdowncCsVtjdd�}|jttdd��|j}~x|D]}|j�q>WdS)Nr,r+re)rrErgrhrCr`ra)r%r0Zthreadsrrrr�test_del_shutdown�s	
z(ThreadPoolShutdownTest.test_del_shutdownN)r'r(r)r3rbrirjrrrrrY~s		rYc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ProcessPoolShutdownTestcCsdS)Nr)r%rrrr3�sz'ProcessPoolShutdownTest._prime_executorcCs�|jjtdd�|jjtdd�|jjtdd�|jt|jj�d�|jj}|jj�x|j�D]}|j�q�WdS)NrZrIr[r\r]r^r+)	r0r?rrPr_�
_processesr:�valuesra)r%�	processes�prrr�test_processes_terminate�s
z0ProcessPoolShutdownTest.test_processes_terminatecCs�tjdd��Y}|j}|jt|jttdd���ddddddddddg
�WdQRXx|j�D]}|j	�q{WdS)	Nr,r+rcr]rIrdrre)
rrGrlrPrfrgrhrCrmra)r%r4rnrorrrri�s	$,z5ProcessPoolShutdownTest.test_context_manager_shutdowncCsutjdd�}t|jttdd���|j}|j}~|j�x|j	�D]}|j�q]WdS)Nr,r+re)
rrGrfrgrhrCZ_queue_management_threadrlrarm)r%r0Zqueue_management_threadrnrorrrrj�s		
z)ProcessPoolShutdownTest.test_del_shutdownN)r'r(r)r3rprirjrrrrrk�s	rkc@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�	WaitTestscCs�|jjtdd�}|jjtjd�}tjt||gdtj�\}}|j	t
|g�|�|j	t
t|g�|�dS)NrZrIg�?�return_when)r0r?rrrrr6�CANCELLED_FUTURE�FIRST_COMPLETEDrP�set)r%�future1�future2�doneZnot_donerrr�test_first_completed�szWaitTests.test_first_completedcCsx|jjtjd�}tjtt|gdtj�\}}|j	t
ttg�|�|j	t
|g�|�dS)Ng�?rr)r0r?rrrr6�CANCELLED_AND_NOTIFIED_FUTURE�SUCCESSFUL_FUTURErtrPru)r%rv�finished�pendingrrr�+test_first_completed_some_already_completed�sz5WaitTests.test_first_completed_some_already_completedcCs�|jjtdd�}|jjtd�}|jjtjd�}tj|||gdtj�\}}|j	t
||g�|�|j	t
|g�|�dS)NrIrZg�?r]rr)r0r?rrrrrr6�FIRST_EXCEPTIONrPru)r%rvrwZfuture3r|r}rrr�test_first_exception�szWaitTests.test_first_exceptioncCs�|jjtdd�}|jjtjd�}tjttt	||gdtj
�\}}|jttt	|g�|�|jtt|g�|�dS)NrZrg�?rr)
r0r?�divmodrrrr6r{rsrzrrPru)r%rvrwr|r}rrr�*test_first_exception_some_already_complete�sz4WaitTests.test_first_exception_some_already_completecCsr|jjtjd�}tjt|gdtj�\}}|jt	tg�|�|jt	|g�|�dS)NrIrr)
r0r?rrrr6�EXCEPTION_FUTURErrPru)r%rvr|r}rrr�'test_first_exception_one_already_failed�sz1WaitTests.test_first_exception_one_already_failedcCs�|jjtdd�}|jjtdd�}tjttt||gdtj	�\}}|j
tttt||g�|�|j
t�|�dS)NrIrrZrr)r0r?r�rrr6r{rzr��
ALL_COMPLETEDrPru)r%rvrwr|r}rrr�test_all_completeds	zWaitTests.test_all_completedcCs�|jjtdd�}|jjtjd�}tjttt	||gdddtj
�\}}|jtttt	|g�|�|jt|g�|�dS)Nr[r\�timeoutr+rr)
r0r?rrrrr6rzr�r{r�rPru)r%rvrwr|r}rrr�test_timeoutszWaitTests.test_timeoutN)
r'r(r)ryr~r�r�r�r�r�rrrrrq�s
rqc@seZdZdd�ZdS)�ThreadPoolWaitTestscs�tj���fdd��tj�}tjd�zF��fdd�td�D�}�j�tj|dtj	�Wdtj|�XdS)Ncs�j�dS)N)r6r)�eventrr�future_func-sz@ThreadPoolWaitTests.test_pending_calls_race.<locals>.future_funcg���ư>cs"h|]}�jj���qSr)r0r?)r@�i)r�r%rr�	<setcomp>2s	z>ThreadPoolWaitTests.test_pending_calls_race.<locals>.<setcomp>�drr)
r�Eventr�getswitchinterval�setswitchintervalrCrurr6r�)r%ZoldswitchintervalrWr)r�r�r%r�test_pending_calls_race)s
"
z+ThreadPoolWaitTests.test_pending_calls_raceN)r'r(r)r�rrrrr�'sr�c@seZdZdS)�ProcessPoolWaitTestsN)r'r(r)rrrrr�9sr�c@s4eZdZdd�Zdd�Zdd�ZdS)�AsCompletedTestscCs}|jjtdd�}|jjtdd�}ttjttt||g��}|j	tttt||g�|�dS)NrIrZr\r[)
r0r?rrur�as_completedrzr�r{rP)r%rvrw�	completedrrr�test_no_timeout?s		z AsCompletedTests.test_no_timeoutc
Cs�|jjtjd�}t�}y=x6tjttt	|gdd�D]}|j
|�qFWWntjk
ruYnX|jtttt	g�|�dS)NrIr�r)
r0r?rrrurr�rzr�r{�add�TimeoutErrorrP)r%rvZcompleted_futures�futurerrr�test_zero_timeoutOs 			
	z"AsCompletedTests.test_zero_timeoutcCsT|jjtjd�}dd�tj||g�D�}|jt|�d�dS)NrIcSsg|]}|�qSrr)r@rrrrrBfs	z;AsCompletedTests.test_duplicate_futures.<locals>.<listcomp>rd)r0r?rrrr�rPr_)r%rvr�rrr�test_duplicate_futuresbs"z'AsCompletedTests.test_duplicate_futuresN)r'r(r)r�r�r�rrrrr�=sr�c@seZdZdS)�ThreadPoolAsCompletedTestsN)r'r(r)rrrrr�jsr�c@seZdZdS)�ProcessPoolAsCompletedTestsN)r'r(r)rrrrr�nsr�c@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	j
jd
d��Zdd�Z
dS)�ExecutorTestcCs2|jjtdd�}|jd|j��dS)NrI��)r0r?rLrPr)r%r�rrr�test_submituszExecutorTest.test_submitcCs5|jjtddd�}|jd|j��dS)NrIrr��)r0r?rrPr)r%r�rrr�test_submit_keywordysz ExecutorTest.test_submit_keywordcCsV|jt|jjttd�td���ttttd�td����dS)N�
)rPrfr0rgrLrC)r%rrr�test_map}s'zExecutorTest.test_mapcCss|jjtddddgddddg�}|j|j�d�|j|j�d�|jt|j�dS)NrdrIr]rr+)rrd)rrd)r0rgr�rP�__next__rJ�ZeroDivisionError)r%r�rrr�test_map_exception�s0zExecutorTest.test_map_exceptioncCs�g}yCx<|jjtjdddgdd�D]}|j|�q1WWntjk
r`YnX|jd�|jddg|�dS)Nrr[r�r+zexpected TimeoutError)	r0rgrr�appendrr�ZfailrP)r%Zresultsr�rrr�test_map_timeout�s

zExecutorTest.test_map_timeoutcCs2|jjtdg|jd�|jj�dS)NrIrd)r0rgr2r/r:)r%rrr�test_shutdown_race_issue12456�s!z*ExecutorTest.test_shutdown_race_issue12456csot�}tj��tj|�fdd��}|jj|j�~�jdd�}|j	|d�dS)Ncs
�j�S)N)ru)�obj)�my_object_collectedrr�<lambda>�sz7ExecutorTest.test_no_stale_references.<locals>.<lambda>r�g@z-Stale reference not collected within timeout.)
r$rr��weakref�refr0r?r&r6�
assertTrue)r%Z	my_objectZmy_object_callbackZ	collectedr)r�r�test_no_stale_references�s		z%ExecutorTest.test_no_stale_referencescCs?x8dD]0}|jtd��|jd|�WdQRXqWdS)Nrrdz"max_workers must be greater than 0r,���)rr�)ZassertRaisesRegex�
ValueErrorr.)r%Znumberrrr�test_max_workers_negative�s
	
z&ExecutorTest.test_max_workers_negativeN)r'r(r)r�r�r�r�r�r�r;r<Zcpython_onlyr�r�rrrrr�rsr�c@s(eZdZdd�Zdd�ZdS)�ThreadPoolExecutorTestcs^g��fdd�}|jj|td��|jjdd�|j�td��dS)zTests verifying issue 11777.cs�j|�dS)N)r�)�n)r|rr�record_finished�szRThreadPoolExecutorTest.test_map_submits_without_iteration.<locals>.record_finishedr�r6TN)r0rgrCr:ZassertCountEqual)r%r�r)r|r�"test_map_submits_without_iteration�s
z9ThreadPoolExecutorTest.test_map_submits_without_iterationcCs3|j�}|j|jtj�p'dd�dS)Nrdr+)r.rPZ_max_workers�os�	cpu_count)r%r0rrr�test_default_workers�sz+ThreadPoolExecutorTest.test_default_workersN)r'r(r)r�r�rrrrr��s
r�c@sFeZdZdd�Zdd�Zedd��Zdd�Zd	S)
�ProcessPoolExecutorTestcCs�|jjtjd�g}tt|jjj���}|j�x!|D]}|j	t
|j�qJW|j	t
|jjtdd�dS)Nr]rIr�)
r0r?rr�next�iterrlrmZ	terminaterJrrrL)r%rroZfutrrr�test_killed_child�s

z)ProcessPoolExecutorTest.test_killed_childcs��fdd�}ttttd�td���}�jt�jjttd�td�dd��|��jt�jjttd�td�dd��|��jt�jjttd�td�dd��|��jt|�dS)Ncs2t�jjttd�td�dd��dS)N�(�	chunksizerdr�)rfr0rgrLrCr)r%rr�bad_map�sz;ProcessPoolExecutorTest.test_map_chunksize.<locals>.bad_mapr�r�r[rV)rfrgrLrCrPr0rJr�)r%r�r�r)r%r�test_map_chunksize�s$---z*ProcessPoolExecutorTest.test_map_chunksizecCstd��dS)N�{)rK)�clsrrr�_test_traceback�sz'ProcessPoolExecutorTest._test_tracebackcCs|jj|j�}|jt��}|j�WdQRX|j}|jt|�t	�|j
|jd�|j}|jt|�t
jj�|jd|j�tjj��9}y
|�Wn%t	k
r�tjtj��YnXWdQRX|jd|j��dS)Nr�z&raise RuntimeError(123) # some comment)r�)r0r?r�rJrrrZassertIs�typerKrP�args�	__cause__rZprocessZ_RemoteTraceback�assertIn�tbr;r<�captured_stderrr�
excepthook�exc_info�getvalue)r%r��cm�exc�cause�f1rrr�test_traceback�s 		

	z&ProcessPoolExecutorTest.test_tracebackN)r'r(r)r�r��classmethodr�r�rrrrr��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#S)$�FutureTestscsOd��fdd�}t�}|j|�|jd�|jd��dS)Ncs|j��dS)N)r)�callback_future)�callback_resultrr�fnsz6FutureTests.test_done_callback_with_result.<locals>.fnr+)r
�add_done_callback�
set_resultrP)r%r�rr)r�r�test_done_callback_with_result�s	

z*FutureTests.test_done_callback_with_resultcsXd��fdd�}t�}|j|�|jtd��|jd�j�dS)Ncs|j��dS)N)r)r�)�callback_exceptionrrr�sz9FutureTests.test_done_callback_with_exception.<locals>.fnr;)r;)r
r��
set_exceptionrrPr�)r%r�rr)r�r�!test_done_callback_with_exception
s	
z-FutureTests.test_done_callback_with_exceptioncsRd��fdd�}t�}|j|�|j|j��|j��dS)Ncs|j��dS)N)�	cancelled)r�)�
was_cancelledrrr�sz6FutureTests.test_done_callback_with_cancel.<locals>.fn)r
r�r��cancel)r%r�rr)r�r�test_done_callback_with_cancels	
z*FutureTests.test_done_callback_with_cancelc
s�tjj���}d�d��fdd�}�fdd�}t�}|j|�|j|�|jd�|j��|j��|jd|j��WdQRXdS)NFcsd�td��dS)NTzdoh!)r)r�)�raising_was_calledrr�
raising_fn%sz9FutureTests.test_done_callback_raises.<locals>.raising_fncs
d�dS)NTr)r�)�
fn_was_calledrrr�*sz1FutureTests.test_done_callback_raises.<locals>.fnr+zException: doh!)	r;r<r�r
r�r�r�r�r�)r%�stderrr�r�rr)r�r�r�test_done_callback_raises s	




z%FutureTests.test_done_callback_raisescsOd��fdd�}t�}|jd�|j|�|jd��dS)Ncs|j��dS)N)r)r�)r�rrr�8sz=FutureTests.test_done_callback_already_successful.<locals>.fnr+)r
r�r�rP)r%r�rr)r�r�%test_done_callback_already_successful6s	

z1FutureTests.test_done_callback_already_successfulcsXd��fdd�}t�}|jtd��|j|�|jd�j�dS)Ncs|j��dS)N)r)r�)r�rrr�Csz9FutureTests.test_done_callback_already_failed.<locals>.fnr;)r;)r
r�rr�rPr�)r%r�rr)r�r�!test_done_callback_already_failedAs	
z-FutureTests.test_done_callback_already_failedcsRd��fdd�}t�}|j|j��|j|�|j��dS)Ncs|j��dS)N)r�)r�)r�rrr�Nsz<FutureTests.test_done_callback_already_cancelled.<locals>.fn)r
r�r�r�)r%r�rr)r�r�$test_done_callback_already_cancelledLs	
z0FutureTests.test_done_callback_already_cancelledcCs�|jtt�d�|jtt�d�|jtt�d�|jtt�d�|jtt�d�|jtt�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>)ZassertRegex�repr�PENDING_FUTURE�RUNNING_FUTURErsrzr�r{)r%rrr�	test_reprWs		zFutureTests.test_reprcCsQtdt�}tdt�}tdt�}tdt�}tdtdt��}tdtdd�}|j|j��|j	|j
t�|j|j��|j	|j
t�|j|j��|j	|j
t�|j|j��|j	|j
t�|j|j��|j	|j
t�|j|j��|j	|j
t�dS)Nrrrr+)rrrrrr	�OSErrorr�r�rPrrO)r%r��f2Zf3Zf4Zf5Zf6rrr�test_cancelhs$zFutureTests.test_cancelcCsv|jtj��|jtj��|jtj��|jtj��|jtj��|jtj��dS)N)	rOr�r�r�r�rsrzr�r{)r%rrr�test_cancelled�szFutureTests.test_cancelledcCsv|jtj��|jtj��|jtj��|jtj��|jtj��|jtj��dS)N)	rOr�rxr�r�rsrzr�r{)r%rrr�	test_done�szFutureTests.test_donecCsv|jtj��|jtj��|jtj��|jtj��|jtj��|jtj��dS)N)	rOr�Zrunningr�r�rsrzr�r{)r%rrr�test_running�szFutureTests.test_runningcCs�|jtjtjdd�|jtjtjdd�|jtjtjdd�|jtjtjdd�|jt	t
jdd�|jtjdd�d�dS)Nr�rr)
rJrr�r�rr��CancelledErrorrsrzr�r�rPr{)r%rrr�test_result_with_timeout�sz$FutureTests.test_result_with_timeoutcs]�fdd�}tdt��tjd|�}|j�|j�jdd�d�dS)Ncstjd��jd�dS)Nrdr)rrr�r)r�rr�notification�s
z:FutureTests.test_result_with_success.<locals>.notificationr�targetr�r+r)rrr�Thread�startrPr)r%r�rr)r�r�test_result_with_success�s

z$FutureTests.test_result_with_successcs]�fdd�}tdt��tjd|�}|j�|jtj�jdd�dS)Ncstjd��j�dS)Nrd)rrr�r)r�rrr��s
z9FutureTests.test_result_with_cancel.<locals>.notificationrr�r�r+)	rrrr�r�rJrr�r)r%r�rr)r�r�test_result_with_cancel�s

z#FutureTests.test_result_with_cancelcCs�|jtjtjdd�|jtjtjdd�|jtjtjdd�|jtjtjdd�|j	t
tjdd�t��|j
tjdd�d�dS)Nr�r)rJrr�r�rr�r�rsrzr��
isinstancer�r�rPr{)r%rrr�test_exception_with_timeout�s
z'FutureTests.test_exception_with_timeoutcsc�fdd�}tdt��tjd|�}|j�|jt�jdd�t��dS)Nc	sDtjd��j�'t�_t��_�jj�WdQRXdS)Nrd)rrZ
_conditionr	rr�r
Z
notify_allr)r�rrr��s


	z=FutureTests.test_exception_with_success.<locals>.notificationrr�r�r+)	rrrr�r�r�rrr�)r%r�rr)r�r�test_exception_with_success�s

z'FutureTests.test_exception_with_successN)r'r(r)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrr��s"


r�c
Cs)ztjjt�Wdtjj�XdS)N)r;r<Zrun_unittestr'Z
reap_childrenrrrr�	test_main�sr�__main__)8Ztest.supportr;r<�
import_moduleZtest.support.script_helperrr�rrrZunittestr�Z
concurrentrZconcurrent.futures._baserrrrr	r
Zconcurrent.futures.processrrr�r�rsrzr�r�r{rrr#�objectr$r*rDrFrHZTestCaserYrkrqr�r�r�r�r�r�r�r�r�Zreap_threadsrr'rrrr�<module>sV. $e-C8�