Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_concurrent_futures.cpython-34.pyo

�
f f]�@s\ddlZejjd�ejjd�ejjd�ddlmZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZmZmZmZmZmZddlmZeddd	d
�Zede�Zede�Zede�Zede�Zedede��Zeded
d�Zdd�Zdd�Zdd�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'�Z/Gd/d0�d0�Z0Gd1d2�d2e$e0e	j'�Z1Gd3d4�d4e%e0e	j'�Z2Gd5d6�d6e	j'�Z3ejj4d7d8��Z5e6d9krXe5�ndS):�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/python34/lib64/python3.4/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_print2s

r#c@seZdZdd�ZdS)�MyObjectcCsdS)Nr)�selfrrr�	my_method9szMyObject.my_methodN)�__name__�
__module__�__qualname__r&rrrrr$8s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�setUp@s&zExecutorMixin.setUpcCs`|jjdd�tj�|j}tjjrItd|dd�n|j|dd�dS)N�waitTz%.2fs�end� �<z+synchronization issue: test lasted too long)	r0�shutdownrr-�test�support�verboserZ
assertLess)r%Zdtrrr�tearDownHs
zExecutorMixin.tearDowncsA�fdd�t�j�D�}x|D]}|j�q)WdS)Ncs(g|]}�jjtjd��qS)g�������?)r0�submitrr)�.0�_)r%rr�
<listcomp>Rs	z1ExecutorMixin._prime_executor.<locals>.<listcomp>)�ranger/r)r%rrr)r%rr3Os
zExecutorMixin._prime_executorN)r'r(r)r/r5r>r3rrrrr*=sr*c@seZdZejZdS)�ThreadPoolMixinN)r'r(r)r�ThreadPoolExecutorr.rrrrrDYs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_shutdownbs
		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_shutdownhs$
z.ExecutorShutdownTest.test_interpreter_shutdowncsK�fdd�td�D�}�jj�x|D]}|j�q3WdS)Ncs(g|]}�jjtjd��qS)g�������?)r0r?rr)r@rA)r%rrrBws	z=ExecutorShutdownTest.test_hang_issue12364.<locals>.<listcomp>�2)rCr0r:r)r%�fsrr)r%r�test_hang_issue12364vs

z)ExecutorShutdownTest.test_hang_issue12364N)r'r(r)rMrUrXrrrrrHasrHc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ThreadPoolShutdownTestcCsdS)Nr)r%rrrr3~sz&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
�WdQXx|jD]}|j�qtWdS)	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
�WdQXx|j�D]}|j	�qzWdS)	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>1s	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�8s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_timeoutNs 			
	z"AsCompletedTests.test_zero_timeoutcCsT|jjtjd�}dd�tj||g�D�}|jt|�d�dS)NrIcSsg|]}|�qSrr)r@rrrrrBes	z;AsCompletedTests.test_duplicate_futures.<locals>.<listcomp>rd)r0r?rrrr�rPr_)r%rvr�rrr�test_duplicate_futuresas"z'AsCompletedTests.test_duplicate_futuresN)r'r(r)r�r�r�rrrrr�<sr�c@seZdZdS)�ThreadPoolAsCompletedTestsN)r'r(r)rrrrr�isr�c@seZdZdS)�ProcessPoolAsCompletedTestsN)r'r(r)rrrrr�msr�c@speZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	j
jd
d��ZdS)�ExecutorTestcCs2|jjtdd�}|jd|j��dS)NrI��)r0r?rLrPr)r%r�rrr�test_submittszExecutorTest.test_submitcCs5|jjtddd�}|jd|j��dS)NrIrr��)r0r?rrPr)r%r�rrr�test_submit_keywordxsz 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_referencesN)
r'r(r)r�r�r�r�r�r�r;r<Zcpython_onlyr�rrrrr�qsr�c@seZdZdd�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_iterationN)r'r(r)r�rrrrr��sr�c@seZdZdd�ZdS)�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_childN)r'r(r)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�fn�sz6FutureTests.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;)ztest)r
r��
set_exceptionrrP�args)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_cancel�s	
z*FutureTests.test_done_callback_with_cancelc
s�tjj���}d�d��fdd�}�fdd�}t�}|j|�|j|�|jd�|j��|j��|jd|j��WdQXdS)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<Zcaptured_stderrr
r�r�r�ZassertIn�getvalue)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�sz=FutureTests.test_done_callback_already_successful.<locals>.fnr+)r
r�r�rP)r%r�rr)r�r�%test_done_callback_already_successful�s	

z1FutureTests.test_done_callback_already_successfulcsXd��fdd�}t�}|jtd��|j|�|jd�j�dS)Ncs|j��dS)N)r)r�)r�rrr�sz9FutureTests.test_done_callback_already_failed.<locals>.fnr;)ztest)r
r�rr�rPr�)r%r�rr)r�r�!test_done_callback_already_failed
s	
z-FutureTests.test_done_callback_already_failedcsRd��fdd�}t�}|j|j��|j|�|j��dS)Ncs|j��dS)N)r�)r�)r�rrr�sz<FutureTests.test_done_callback_already_cancelled.<locals>.fn)r
r�r�r�)r%r�rr)r�r�$test_done_callback_already_cancelleds	
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_repr s		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%�f1�f2Zf3Zf4Zf5Zf6rrr�test_cancel1s$zFutureTests.test_cancelcCsv|jtj��|jtj��|jtj��|jtj��|jtj��|jtj��dS)N)	rOr�r�r�r�rsrzr�r{)r%rrr�test_cancelledKszFutureTests.test_cancelledcCsv|jtj��|jtj��|jtj��|jtj��|jtj��|jtj��dS)N)	rOr�rxr�r�rsrzr�r{)r%rrr�	test_doneSs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_timeoutcsz$FutureTests.test_result_with_timeoutcs]�fdd�}tdt��tjd|�}|j�|j�jdd�d�dS)Ncstjd��jd�dS)Nrdr)rrr�r)r�rr�notificationqs
z:FutureTests.test_result_with_success.<locals>.notificationr�targetr�r+r)rrr�Thread�startrPr)r%r�rr)r�r�test_result_with_successos

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	sCtjd��j�'t�_t��_�jj�WdQXdS)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�r�rr�)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�r�r�rrrrr��s"


r�c
Cs)ztjjt�Wdtjj�XdS)N)r;r<Zrun_unittestr'Z
reap_childrenrrrr�	test_main�sr��__main__)7Ztest.supportr;r<�
import_moduleZtest.script_helperrrrrZunittestr�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_threadsr�r'rrrr�<module>sT. $e-<�