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.opt-2.pyc



���]e�@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):�N�_multiprocessingzmultiprocessing.synchronize�	threading)�assert_python_ok)�futures)�PENDING�RUNNING�	CANCELLED�CANCELLED_AND_NOTIFIED�FINISHED�Future)�BrokenProcessPoolcCs(t�}||_||_||_|S)N)r�_state�
_exception�_result)�state�	exception�result�f�r�</opt/alt/python35/lib64/python3.5/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)	r2�shutdownrr/�test�support�verboser Z
assertLess)r'Zdtrrr�tearDownIs
zExecutorMixin.tearDowncsA�fdd�t�j�D�}x|D]}|j�q)WdS)Ncs(g|]}�jjtjd��qS)g�������?)r2�submitrr)�.0�_)r'rr�
<listcomp>Ss	z1ExecutorMixin._prime_executor.<locals>.<listcomp>)�ranger1r)r'rrr)r'rr5Ps
zExecutorMixin._prime_executorN)r)r*r+r1r7r@r5rrrrr,>sr,c@seZdZejZdS)�ThreadPoolMixinN)r)r*r+r�ThreadPoolExecutorr0rrrrrFZsrFc@seZdZejZdS)�ProcessPoolMixinN)r)r*r+r�ProcessPoolExecutorr0rrrrrH^srHc@s4eZdZdd�Zdd�Zdd�ZdS)�ExecutorShutdownTestcCs0|jj�|jt|jjtdd�dS)N�r-)r2r<�assertRaises�RuntimeErrorrA�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")
            r0sapple)r�formatr0r)�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�������?)r2rArr)rBrC)r'rrrDxs	z=ExecutorShutdownTest.test_hang_issue12364.<locals>.<listcomp>�2)rEr2r<r)r'�fsrr)r'r�test_hang_issue12364ws

z)ExecutorShutdownTest.test_hang_issue12364N)r)r*r+rOrWrZrrrrrJbsrJc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ThreadPoolShutdownTestcCsdS)Nr)r'rrrr5sz&ThreadPoolShutdownTest._prime_executorcCs�|jjtdd�|jjtdd�|jjtdd�|jt|jj�d�|jj�x|jjD]}|j�qxWdS)N�rK����)r2rArrR�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_rK�r���)	rrGrR�list�map�absrErbrc)r'r6r2rrrr�test_context_manager_shutdown�s$,z4ThreadPoolShutdownTest.test_context_manager_shutdowncCsVtjdd�}|jttdd��|j}~x|D]}|j�q>WdS)Nr.r-rg)rrGrirjrErbrc)r'r2�threadsrrrr�test_del_shutdown�s	
z(ThreadPoolShutdownTest.test_del_shutdownN)r)r*r+r5rdrkrmrrrrr[~s		r[c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ProcessPoolShutdownTestcCsdS)Nr)r'rrrr5�sz'ProcessPoolShutdownTest._prime_executorcCs�|jjtdd�|jjtdd�|jjtdd�|jt|jj�d�|jj}|jj�x|j�D]}|j�q�WdS)Nr\rKr]r^r_r`r-)	r2rArrRra�
_processesr<�valuesrc)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-rer_rKrfrrg)
rrIrorRrhrirjrErprc)r'r6rqrrrrrrk�s	$,z5ProcessPoolShutdownTest.test_context_manager_shutdowncCsutjdd�}t|jttdd���|j}|j}~|j�x|j	�D]}|j�q]WdS)Nr.r-rg)
rrIrhrirjrE�_queue_management_threadrorcrp)r'r2Zqueue_management_threadrqrrrrrrm�s		
z)ProcessPoolShutdownTest.test_del_shutdownN)r)r*r+r5rsrkrmrrrrrn�s	rnc@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�	WaitTestscCs�|jjtdd�}|jjtjd�}tjt||gdtj�\}}|j	t
|g�|�|j	t
t|g�|�dS)Nr\rKg�?�return_when)r2rArrrrr8�CANCELLED_FUTURE�FIRST_COMPLETEDrR�set)r'�future1�future2�done�not_donerrr�test_first_completed�szWaitTests.test_first_completedcCsx|jjtjd�}tjtt|gdtj�\}}|j	t
ttg�|�|j	t
|g�|�dS)Ng�?rv)r2rArrrr8�CANCELLED_AND_NOTIFIED_FUTURE�SUCCESSFUL_FUTURErxrRry)r'rz�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)NrKr\g�?r_rv)r2rArrrrrr8�FIRST_EXCEPTIONrRry)r'rzr{Zfuture3r�r�rrr�test_first_exception�szWaitTests.test_first_exceptioncCs�|jjtdd�}|jjtjd�}tjttt	||gdtj
�\}}|jttt	|g�|�|jtt|g�|�dS)Nr\rg�?rv)
r2rA�divmodrrrr8r�rwrr�rRry)r'rzr{r�r�rrr�*test_first_exception_some_already_complete�sz4WaitTests.test_first_exception_some_already_completecCsr|jjtjd�}tjt|gdtj�\}}|jt	tg�|�|jt	|g�|�dS)NrKrv)
r2rArrrr8�EXCEPTION_FUTUREr�rRry)r'rzr�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)NrKrr\rv)r2rAr�rrr8r�rr��
ALL_COMPLETEDrRry)r'rzr{r�r�rrr�test_all_completeds	zWaitTests.test_all_completedcCs�|jjtdd�}|jjtjd�}tjttt	||gdddtj
�\}}|jtttt	|g�|�|jt|g�|�dS)Nr]r^�timeoutr-rv)
r2rArrrrr8rr�r�r�rRry)r'rzr{r�r�rrr�test_timeoutszWaitTests.test_timeoutN)
r)r*r+r~r�r�r�r�r�r�rrrrru�s
ruc@seZdZdd�ZdS)�ThreadPoolWaitTestscs�tj���fdd��tj�}tjd�zF��fdd�td�D�}�j�tj|dtj	�Wdtj|�XdS)Ncs�j�dS)N)r8r)�eventrr�future_func-sz@ThreadPoolWaitTests.test_pending_calls_race.<locals>.future_funcg���ư>cs"h|]}�jj���qSr)r2rA)rB�i)r�r'rr�	<setcomp>2s	z>ThreadPoolWaitTests.test_pending_calls_race.<locals>.<setcomp>�drv)
r�Eventr!�getswitchinterval�setswitchintervalrEryrr8r�)r'ZoldswitchintervalrYr)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)NrKr\r^r])
r2rArryr�as_completedrr�r�rR)r'rzr{�	completedrrr�test_no_timeout?s		z AsCompletedTests.test_no_timeoutc
Cs�|jjtjd�}t�}y=x6tjttt	|gdd�D]}|j
|�qFWWntjk
ruYnX|jtttt	g�|�dS)NrKr�r)
r2rArrryrr�rr�r��add�TimeoutErrorrR)r'rzZcompleted_futures�futurerrr�test_zero_timeoutOs 			
	z"AsCompletedTests.test_zero_timeoutcCsT|jjtjd�}dd�tj||g�D�}|jt|�d�dS)NrKcSsg|]}|�qSrr)rBrrrrrDfs	z;AsCompletedTests.test_duplicate_futures.<locals>.<listcomp>rf)r2rArrrr�rRra)r'rzr�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)NrK��)r2rArNrRr)r'r�rrr�test_submituszExecutorTest.test_submitcCs5|jjtddd�}|jd|j��dS)NrKrr��)r2rArrRr)r'r�rrr�test_submit_keywordysz ExecutorTest.test_submit_keywordcCsV|jt|jjttd�td���ttttd�td����dS)N�
)rRrhr2rirNrE)r'rrr�test_map}s'zExecutorTest.test_mapcCss|jjtddddgddddg�}|j|j�d�|j|j�d�|jt|j�dS)NrfrKr_rr-)rrf)rrf)r2rir�rR�__next__rL�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)	r2rirr�appendrr�ZfailrR)r'�resultsr�rrr�test_map_timeout�s

zExecutorTest.test_map_timeoutcCs2|jjtdg|jd�|jj�dS)NrKrf)r2rir4r1r<)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)ry)�obj)�my_object_collectedrr�<lambda>�sz7ExecutorTest.test_no_stale_references.<locals>.<lambda>r�g@z-Stale reference not collected within timeout.)
r&rr��weakref�refr2rAr(r8�
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)Nrrfz"max_workers must be greater than 0r.���)rr�)ZassertRaisesRegex�
ValueErrorr0)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)Ncs�j|�dS)N)r�)�n)r�rr�record_finished�szRThreadPoolExecutorTest.test_map_submits_without_iteration.<locals>.record_finishedr�r8T)r2rirEr<ZassertCountEqual)r'r�r)r�r�"test_map_submits_without_iteration�s
z9ThreadPoolExecutorTest.test_map_submits_without_iterationcCs3|j�}|j|jtj�p'dd�dS)Nrfr-)r0rR�_max_workers�os�	cpu_count)r'r2rrr�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_rKr�)
r2rArr�next�iterrorp�	terminaterLrrrN)r'rrrZfutrrr�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�(�	chunksizerfr�)rhr2rirNrEr)r'rr�bad_map�sz;ProcessPoolExecutorTest.test_map_chunksize.<locals>.bad_mapr�r�r]rX)rhrirNrErRr2rLr�)r'r�r�r)r'r�test_map_chunksize�s$---z*ProcessPoolExecutorTest.test_map_chunksizecCstd��dS)N�{)rM)�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�)r2rAr�rLrrrZassertIs�typerMrR�args�	__cause__r�process�_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_resultrR)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=)rr��
set_exceptionrrRr�)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)rr�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�rr�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-)rr�r�rR)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=)rr�rr�rRr�)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)rr�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_FUTURErwrr�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-)rrrrr	r
�OSErrorr�r�rRr
rQ)r'r��f2Zf3Zf4Zf5Zf6rrr�test_cancelhs$zFutureTests.test_cancelcCsv|jtj��|jtj��|jtj��|jtj��|jtj��|jtj��dS)N)	rQr�r�r�r�rwrr�r�)r'rrr�test_cancelled�szFutureTests.test_cancelledcCsv|jtj��|jtj��|jtj��|jtj��|jtj��|jtj��dS)N)	rQr�r|r�r�rwrr�r�)r'rrr�	test_done�szFutureTests.test_donecCsv|jtj��|jtj��|jtj��|jtj��|jtj��|jtj��dS)N)	rQr��runningr�r�rwrr�r�)r'rrr�test_running�szFutureTests.test_runningcCs�|jtjtjdd�|jtjtjdd�|jtjtjdd�|jtjtjdd�|jt	t
jdd�|jtjdd�d�dS)Nr�rr)
rLrr�r�rr��CancelledErrorrwrr�r�rRr�)r'rrr�test_result_with_timeout�sz$FutureTests.test_result_with_timeoutcs]�fdd�}tdt��tjd|�}|j�|j�jdd�d�dS)Ncstjd��jd�dS)Nrfr)rrr�r)r�rr�notification�s
z:FutureTests.test_result_with_success.<locals>.notificationr�targetr�r-r)rrr�Thread�startrRr)r'rrr)r�r�test_result_with_success�s

z$FutureTests.test_result_with_successcs]�fdd�}tdt��tjd|�}|j�|jtj�jdd�dS)Ncstjd��j�dS)Nrf)rrr�r)r�rrr�s
z9FutureTests.test_result_with_cancel.<locals>.notificationrrr�r-)	rrrrrrLrrr)r'rrr)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)rLrr�r�rr�rrwrr��
isinstancer�r�rRr�)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)Nrf)rr�
_conditionr
r
r�r�
notify_allr)r�rrr�s


	z=FutureTests.test_exception_with_success.<locals>.notificationrrr�r-)	rrrrrr�rrr�)r'rrr)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�rrrr	r
rrrrrrr��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�r!rrZunittestr�Z
concurrentr�concurrent.futures._baserrrr	r
r�concurrent.futures.processrrr�r�rwrr�r�r�rrr%�objectr&r,rFrHrJZTestCaser[rnrur�r�r�r�r�r�r�r�r�Zreap_threadsrr)rrrr�<module>sV. $e-C8�