a
    3j"                     @   s  d dl mZ ed e  d dlmZ d dlmZ d dlZd dl	Z	d dl
Z
d dlmZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dlmZ d d	lmZmZmZmZmZmZmZ d d
l m!Z! d dl"m#Z# d dl$Z"d dl%Z"eddfddZ&e&edZ'e&edZ(e&edZ)e&edZ*e&ee+ dZ,e&eddZ-da.dd Z/dd Z0dd Z1dd Z2dd Z3dd Z4didd Z5G d!d" d"e6Z7G d#d$ d$Z8d%d& Z9G d'd( d(ej:Z;G d)d* d*Z<G d+d, d,e<Z=G d-d. d.e<Z>G d/d0 d0e<Z?G d1d2 d2e<Z@e;fe=e>e@e?ffd3d4ZAG d5d6 d6e<ZBG d7d8 d8e<ZCeAeB eAeC G d9d: d:ZDG d;d< d<e=eDe;ZEG d=d> d>eDZFeAeFe>e@e?fd? G d@dA dAZGG dBdC dCe=eGe;ZHeAeGe>e@e?fd? G dDdE dEZIeAeI G dFdG dGZJG dHdI dIe=eJe;ZKG dJdK dKeJZLeAeLe>e@e?fd? djdLdMZMdNdO ZNdPdQ ZOdRdS ZPdTdU ZQG dVdW dWe6ZRG dXdY dYe6ZSG dZd[ d[e6ZTG d\d] d]e6ZUG d^d_ d_e6ZVG d`da dae6ZWG dbdc dcZXeAeXe>e@e?fd? G ddde dee;ZYdfdg ZZe[dhkre\  dS )k    )support_multiprocessing)hashlib_helper)assert_python_okN)QueueHandlerPicklingError)futures)PENDINGRUNNING	CANCELLEDCANCELLED_AND_NOTIFIEDFINISHEDFutureBrokenExecutor)BrokenProcessPool)get_contextc                 C   s   t  }| |_||_||_|S N)r   _state
_exception_result)state	exceptionresultf r   X/www/server/python_manager/versions/3.9.10/lib/python3.9/test/test_concurrent_futures.pycreate_future#   s
    r   r   r   r   *   r   r   uninitializedc                 C   s   | | S r   r   )xyr   r   r   mul5   s    r%   c                  O   s   | |fS r   r   )argskwargsr   r   r   capture8   s    r(   c                 C   s   t |  tdd S )Nzthis is an exception)timesleep	Exception)tr   r   r   sleep_and_raise;   s    
r-   c                 C   s    t |  t| tj  d S r   )r)   r*   printsysstdoutflush)r,   msgr   r   r   sleep_and_print?   s    
r3   c                 C   s   | a d S r   INITIALIZER_STATUS)r#   r   r   r   initD   s    r6   c                   C   s   t S r   r4   r   r   r   r   get_init_statusH   s    r7   c                 C   sF   | d ur0t d}|t|  |d d|_td tdd S )Nconcurrent.futuresCRITICALF皙?zerror in initializer)	logging	getLogger
addHandlerr   setLevel	propagater)   r*   
ValueError)	log_queueloggerr   r   r   	init_failK   s    


rC   c                   @   s   e Zd Zdd ZdS )MyObjectc                 C   s   d S r   r   selfr   r   r   	my_methodV   s    zMyObject.my_methodN)__name__
__module____qualname__rG   r   r   r   r   rD   U   s   rD   c                   @   s   e Zd Zdd Zdd ZdS )EventfulGCObjc                 C   s   |  | _d S r   )Eventevent)rF   mgrr   r   r   __init__[   s    zEventfulGCObj.__init__c                 C   s   | j   d S r   )rM   setrE   r   r   r   __del__^   s    zEventfulGCObj.__del__N)rH   rI   rJ   rO   rQ   r   r   r   r   rK   Z   s   rK   c                 C   s   t  S r   )rD   )_r   r   r   make_dummy_objectb   s    rS   c                   @   s   e Zd Zdd Zdd ZdS )BaseTestCasec                 C   s   t  | _d S r   )r   threading_setup_thread_keyrE   r   r   r   setUpg   s    zBaseTestCase.setUpc                 C   s   t   t j| j  d S r   )r   reap_childrenthreading_cleanuprV   rE   r   r   r   tearDownj   s    zBaseTestCase.tearDownN)rH   rI   rJ   rW   rZ   r   r   r   r   rT   f   s   rT   c                       s@   e Zd ZdZi Z fddZ fddZdd Zdd	 Z  Z	S )
ExecutorMixin   c                    sf   t    t | _t| dr@| jf | j|  d| j	| _
n| jf d| ji| j	| _
|   d S )Nctxmax_workers
mp_contextr_   )superrW   r)   	monotonict1hasattrexecutor_typeworker_countr   executor_kwargsexecutor_prime_executorrE   	__class__r   r   rW   s   s    



zExecutorMixin.setUpc                    sT   | j jdd d | _ t | j }tjr8td| dd | |dd t	 
  d S )NTwaitz%.2fs )endi,  z+synchronization issue: test lasted too long)rh   shutdownr)   rb   rc   r   verboser.   Z
assertLessra   rZ   )rF   Zdtrj   r   r   rZ      s    zExecutorMixin.tearDownc                 C   s
   t | jS r   )r   r]   rE   r   r   r   r      s    zExecutorMixin.get_contextc                    s.    fddt  jD }|D ]}|  qd S )Nc                    s   g | ]} j tjd qS r:   rh   submitr)   r*   .0rR   rE   r   r   
<listcomp>   s   z1ExecutorMixin._prime_executor.<locals>.<listcomp>)rangerf   r   rF   r	   r   r   rE   r   ri      s
    
zExecutorMixin._prime_executor)
rH   rI   rJ   rf   rg   rW   rZ   r   ri   __classcell__r   r   rj   r   r[   o   s   r[   c                   @   s   e Zd ZejZdS )ThreadPoolMixinN)rH   rI   rJ   r	   ThreadPoolExecutorre   r   r   r   r   r{      s   r{   c                       s&   e Zd ZejZdZ fddZ  ZS )ProcessPoolForkMixinforkc                    s   t jdkr| d t  S Nwin32zrequire unix systemr/   platformZskipTestra   r   rE   rj   r   r   r      s    

z ProcessPoolForkMixin.get_context	rH   rI   rJ   r	   ProcessPoolExecutorre   r]   r   rz   r   r   rj   r   r}      s   r}   c                   @   s   e Zd ZejZdZdS )ProcessPoolSpawnMixinspawnN)rH   rI   rJ   r	   r   re   r]   r   r   r   r   r      s   r   c                       s&   e Zd ZejZdZ fddZ  ZS )ProcessPoolForkserverMixin
forkserverc                    s   t jdkr| d t  S r   r   rE   rj   r   r   r      s    

z&ProcessPoolForkserverMixin.get_contextr   r   r   rj   r   r      s   r   c                 C   sP   dd }|D ]>}d||j || j f }t|| f|f | i }|t |< qd S )Nc                 S   s4   |  dr| d d S |  dr,| d d S | S d S )N)ZMixinZTestsZTest)endswith)namer   r   r   strip_mixin   s
    

z*create_executor_tests.<locals>.strip_mixinz%s%sTest)rH   typeglobals)Zmixinbasesexecutor_mixinsr   Zexer   clsr   r   r   create_executor_tests   s    r   c                       s(   e Zd ZdZ fddZdd Z  ZS )InitializerMixin   c                    s    da ttdd| _t   d S )Nr"   )initializedinitializerinitargs)r5   dictr6   rg   ra   rW   rE   rj   r   r   rW      s
    zInitializerMixin.setUpc                    s6    fddt  jD }|D ]} | d qd S )Nc                    s   g | ]} j tqS r   )rh   rt   r7   ru   rE   r   r   rw      s   z5InitializerMixin.test_initializer.<locals>.<listcomp>r   )rx   rf   assertEqualr   ry   r   rE   r   test_initializer   s
    
z!InitializerMixin.test_initializer)rH   rI   rJ   rf   rW   r   rz   r   r   rj   r   r      s   r   c                       s>   e Zd ZdZ fddZdd Zdd Zejdd	 Z	  Z
S )
FailingInitializerMixinr   c                    sZ   t | dr4|  | _| j | _tt| jfd| _nd | _d | _ttd| _t 	  d S )Nr]   r   )r   )
rd   r   r`   QueuerA   r   rC   rg   ra   rW   rE   rj   r   r   rW      s    


zFailingInitializerMixin.setUpc              	   C   s   |  d z| jt}W n ty.   Y n40 | t |  W d    n1 sX0    Y  t }| jj	st | dkr| 
d td qj| t | jt W d    n1 s0    Y  W d    n1 s0    Y  d S )Nz ValueError: error in initializerr\   zexecutor not broken after 5 s.g{Gz?)_assert_loggedrh   rt   r7   r   assertRaisesr   r)   rb   _brokenfailr*   )rF   futurerc   r   r   r   r      s    &
z(FailingInitializerMixin.test_initializerc                 C   s   d S r   r   rE   r   r   r   ri     s    z'FailingInitializerMixin._prime_executorc                 #   s   | j d urFd V  g }z|| j    qW q~ tjyB   Y q~0 n8| dd}d V  W d    n1 sn0    Y  |j}| t	 fdd|D | d S )Nr8   r9   c                 3   s   | ]} |v V  qd S r   r   )rv   liner2   r   r   	<genexpr>      z9FailingInitializerMixin._assert_logged.<locals>.<genexpr>)
rA   append
get_nowait
getMessagequeueEmptyZ
assertLogsoutput
assertTrueany)rF   r2   r   cmr   r   r   r     s    
$z&FailingInitializerMixin._assert_logged)rH   rI   rJ   rf   rW   r   ri   
contextlibcontextmanagerr   rz   r   r   rj   r   r      s   r   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )ExecutorShutdownTestc                 C   s$   | j   | t| j jtdd d S )Nr   r\   )rh   rp   r   RuntimeErrorrt   powrE   r   r   r   test_run_after_shutdown  s
    
z,ExecutorShutdownTest.test_run_after_shutdownc                 C   sD   t ddj| jjt| ddd\}}}| | | | d d S )N-caK  if 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   context   apple)r   formatre   rH   getattrassertFalser   striprF   rcouterrr   r   r   test_interpreter_shutdown"  s    

z.ExecutorShutdownTest.test_interpreter_shutdownc                 C   sJ   t ddj| jjt| ddd\}}}| d|  | | d d S )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)	r   r   re   rH   r   assertIndecoder   r   r   r   r   r   &test_submit_after_interpreter_shutdown8  s    
z;ExecutorShutdownTest.test_submit_after_interpreter_shutdownc                    s6    fddt dD } j  |D ]}|  q$d S )Nc                    s   g | ]} j tjd qS rr   rs   ru   rE   r   r   rw   U  r   z=ExecutorShutdownTest.test_hang_issue12364.<locals>.<listcomp>2   )rx   rh   rp   r   )rF   fsr   r   rE   r   test_hang_issue12364T  s    
z)ExecutorShutdownTest.test_hang_issue12364c                    s   | j dd  fddtdD } jdd dd |D }| jt|d	kd
t|d dd |D }|D ],}| j| d|jd | |  qn| jt|dkdt|d d S )N   r_   c                    s   g | ]}  tjd qS rr   )rt   r)   r*   ru   rh   r   r   rw   \  r   z<ExecutorShutdownTest.test_cancel_futures.<locals>.<listcomp>r   T)cancel_futuresc                 S   s   g | ]}|  r|qS r   	cancelledrv   futr   r   r   rw   a  r   #   zlen(cancelled)=r   c                 S   s   g | ]}|  s|qS r   r   r   r   r   r   rw   g  r   zfut._state=r   zlen(others)=)	re   rx   rp   r   lendoner   assertIsNoner   )rF   r   r   Zothersr   r   r   r   test_cancel_futuresZ  s     z(ExecutorShutdownTest.test_cancel_futuresc                 C   sP   | j tjkrtdtddj| j jd\}}}| | | 	|
 d dS )zyshutdown(wait=False) doesn't hang at exit with running futures.

        See https://bugs.python.org/issue39205.
        z/Hangs due to https://bugs.python.org/issue39205r   aN  if True:
            from concurrent.futures import {executor_type}
            from test.test_concurrent_futures import sleep_and_print
            if __name__ == "__main__":
                t = {executor_type}(max_workers=3)
                t.submit(sleep_and_print, 1.0, "apple")
                t.shutdown(wait=False)
            re   r   N)re   r	   r   unittestZSkipTestr   r   rH   r   r   r   r   r   r   r   test_hang_issue39205q  s    
z)ExecutorShutdownTest.test_hang_issue39205N)	rH   rI   rJ   r   r   r   r   r   r   r   r   r   r   r     s   r   c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )ThreadPoolShutdownTestc                 C   s   d S r   r   rE   r   r   r   ri     s    z&ThreadPoolShutdownTest._prime_executorc                 C   s|   dd }t d}tdD ]}| j|| q| t| jjd tdD ]}|  qJ| j	  | jjD ]}|
  qjd S )Nc                 S   s   |    d S r   acquirelockr   r   r   acquire_lock  s    zCThreadPoolShutdownTest.test_threads_terminate.<locals>.acquire_lockr   r   )	threading	Semaphorerx   rh   rt   r   r   _threadsreleaserp   join)rF   r   semir,   r   r   r   test_threads_terminate  s    


z-ThreadPoolShutdownTest.test_threads_terminatec              
   C   sj   t jdd6}|}| t|ttddg d W d    n1 sH0    Y  |jD ]}|  qXd S Nr\   r   r   )
r\      r   r      r   r   r   r   r   )	r	   r|   r   listmapabsrx   r   r   )rF   erh   r,   r   r   r   test_context_manager_shutdown  s    "
z4ThreadPoolShutdownTest.test_context_manager_shutdownc                 C   s^   t jdd}|ttdd}|j}~|D ]}|  q*tdd t|tddD sZJ d S )Nr\   r   r   c                 S   s   g | ]\}}|t |kqS r   r   rv   rvr   r   r   rw     r   z<ThreadPoolShutdownTest.test_del_shutdown.<locals>.<listcomp>)	r	   r|   r   r   rx   r   r   allziprF   rh   resthreadsr,   r   r   r   test_del_shutdown  s    
z(ThreadPoolShutdownTest.test_del_shutdownc                 C   sh   t jdd}|ttdd}|j}|jdd |D ]}|  q4tdd t	|tddD sdJ d S )Nr\   r   r   Frl   c                 S   s   g | ]\}}|t |kqS r   r   r   r   r   r   rw     r   z@ThreadPoolShutdownTest.test_shutdown_no_wait.<locals>.<listcomp>)
r	   r|   r   r   rx   r   rp   r   r   r   r   r   r   r   test_shutdown_no_wait  s    
z,ThreadPoolShutdownTest.test_shutdown_no_waitc                 C   sT   t jddd}|ttdd |j}~t  |D ]}| |j	d |
  q4d S )Nr\   ZSpecialPool)r_   Zthread_name_prefixr   z^SpecialPool_[0-4]$r	   r|   r   r   rx   r   r   
gc_collectassertRegexr   r   rF   rh   r   r,   r   r   r   test_thread_names_assigned  s    z1ThreadPoolShutdownTest.test_thread_names_assignedc                 C   sR   t jdd}|ttdd |j}~t  |D ]}| |j	d |
  q2d S )Nr\   r   r   zThreadPoolExecutor-\d+_[0-4]$r   r   r   r   r   test_thread_names_default  s    z0ThreadPoolShutdownTest.test_thread_names_defaultc                 C   s:   t ddj| jjd\}}}| | | | d d S )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   r   )r   r   re   rH   r   r   r   r   r   r   r   test_cancel_futures_wait_false  s
    

z5ThreadPoolShutdownTest.test_cancel_futures_wait_falseN)rH   rI   rJ   ri   r   r   r   r   r   r  r  r   r   r   r   r     s   	r   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )ProcessPoolShutdownTestc                 C   s   d S r   r   rE   r   r   r   ri     s    z'ProcessPoolShutdownTest._prime_executorc                 C   s   dd }t  }|d}tdD ]}| j|| q | t| jjd tdD ]}|  qP| jj}| j	  |
 D ]}|  qxd S )Nc                 S   s   |    d S r   r   r   r   r   r   r     s    zFProcessPoolShutdownTest.test_processes_terminate.<locals>.acquire_lockr   r   )r   r   rx   rh   rt   r   r   
_processesr   rp   valuesr   )rF   r   r`   r   rR   	processespr   r   r   test_processes_terminate  s    


z0ProcessPoolShutdownTest.test_processes_terminatec              
   C   sn   t jdd8}|j}| t|ttddg d W d    n1 sJ0    Y  | D ]}|	  q\d S r   )
r	   r   r  r   r   r   r   rx   r  r   )rF   r   r  r  r   r   r   r     s    "z5ProcessPoolShutdownTest.test_context_manager_shutdownc                 C   s   t jdd}|ttdd}|j}|j}|j}|j}~t	  |
  | D ]}|
  qP|  tdd t|tddD sJ d S )Nr\   r   r   c                 S   s   g | ]\}}|t |kqS r   r   r   r   r   r   rw     r   z=ProcessPoolShutdownTest.test_del_shutdown.<locals>.<listcomp>)r	   r   r   r   rx   _executor_manager_threadr  _call_queuer   r   r   r  join_threadr   r   )rF   rh   r   executor_manager_threadr  
call_queuer  r   r   r   r     s    
z)ProcessPoolShutdownTest.test_del_shutdownc                 C   s   t jdd}|ttdd}|j}|j}|j}|jdd |	  |
 D ]}|	  qL|  tdd t|tddD sJ d S )Nr\   r   r   Frl   c                 S   s   g | ]\}}|t |kqS r   r   r   r   r   r   rw   -  r   zAProcessPoolShutdownTest.test_shutdown_no_wait.<locals>.<listcomp>)r	   r   r   r   rx   r  r
  r	  rp   r   r  r  r   r   )rF   rh   r   r  r  r  r  r   r   r   r     s    
z-ProcessPoolShutdownTest.test_shutdown_no_waitN)rH   rI   rJ   ri   r  r   r   r   r   r   r   r   r    s
   	r  )r   c                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )	WaitTestsc                 C   sH   | j tjd}tj||gtjd\}}| |h| | t | d S N      ?return_when)	rh   rt   r)   r*   r	   rm   ALL_COMPLETEDr   rP   )rF   r   r   not_doner   r   r   
test_203697  s    

zWaitTests.test_20369c                 C   sd   | j tdd}| j tjd}tjt||gtjd\}}| 	t
|g| | 	t
t|g| d S )N   r   r  r  )rh   rt   r%   r)   r*   r	   rm   CANCELLED_FUTUREFIRST_COMPLETEDr   rP   )rF   future1future2r   r  r   r   r   test_first_completed@  s    
zWaitTests.test_first_completedc                 C   sT   | j tjd}tjtt|gtjd\}}| 	t
ttg| | 	t
|g| d S r  )rh   rt   r)   r*   r	   rm   CANCELLED_AND_NOTIFIED_FUTURESUCCESSFUL_FUTUREr  r   rP   rF   r  finishedpendingr   r   r   +test_first_completed_some_already_completedK  s    

z5WaitTests.test_first_completed_some_already_completedc                 C   sr   | j tdd}| j td}| j tjd}tj|||gtjd\}}| 	t
||g| | 	t
|g| d S )Nr   r  r  r   r  )rh   rt   r%   r-   r)   r*   r	   rm   FIRST_EXCEPTIONr   rP   )rF   r  r  Zfuture3r  r   r   r   r   test_first_exceptionW  s    
zWaitTests.test_first_exceptionc                 C   sl   | j tdd}| j tjd}tjttt	||gtj
d\}}| ttt	|g| | tt|g| d S )Nr  r   r  r  )rh   rt   divmodr)   r*   r	   rm   r  r  r  r"  r   rP   rF   r  r  r  r   r   r   r   *test_first_exception_some_already_completec  s"    
z4WaitTests.test_first_exception_some_already_completec                 C   sP   | j tjd}tjt|gtjd\}}| t	tg| | t	|g| d S )Nr   r  )
rh   rt   r)   r*   r	   rm   EXCEPTION_FUTUREr"  r   rP   r  r   r   r   'test_first_exception_one_already_faileds  s    
z1WaitTests.test_first_exception_one_already_failedc                 C   sj   | j tdd}| j tdd}tjttt||gtj	d\}}| 
tttt||g| | 
t | d S )Nr   r   r  r  )rh   rt   r$  r%   r	   rm   r  r  r'  r  r   rP   r%  r   r   r   test_all_completed}  s(    
zWaitTests.test_all_completedc                 C   sn   | j tdd}| j tjd}tjttt	||gdtj
d\}}| tttt	|g| | t|g| d S )N      r\   )timeoutr  )rh   rt   r%   r)   r*   r	   rm   r  r'  r  r  r   rP   r%  r   r   r   test_timeout  s&    
zWaitTests.test_timeoutN)rH   rI   rJ   r  r  r!  r#  r&  r(  r)  r-  r   r   r   r   r  6  s   	
r  c                   @   s   e Zd Zdd ZdS )ThreadPoolWaitTestsc              	      sv   t    fddt }td z>fddtdD }   tj|tj	d W t| nt| 0 d S )Nc                      s       d S r   rl   r   )rM   r   r   future_func  s    z@ThreadPoolWaitTests.test_pending_calls_race.<locals>.future_funcgư>c                    s   h | ]}j  qS r   )rh   rt   )rv   r   )r/  rF   r   r   	<setcomp>  r   z>ThreadPoolWaitTests.test_pending_calls_race.<locals>.<setcomp>d   r  )
r   rL   r/   getswitchintervalsetswitchintervalrx   rP   r	   rm   r  )rF   Zoldswitchintervalr   r   )rM   r/  rF   r   test_pending_calls_race  s    
z+ThreadPoolWaitTests.test_pending_calls_raceN)rH   rI   rJ   r4  r   r   r   r   r.    s   r.  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )AsCompletedTestsc                 C   sV   | j tdd}| j tdd}ttttt||g}| 	tttt||g| d S )Nr   r  r+  r*  )
rh   rt   r%   rP   r	   as_completedr  r'  r  r   )rF   r  r  	completedr   r   r   test_no_timeout  s$    z AsCompletedTests.test_no_timeoutc                 C   sp   | j tjd}t }z*tjttt	|gddD ]}|
| q.W n tjyT   Y n0 | tttt	g| d S )Nr   r   r,  )rh   rt   r)   r*   rP   r	   r6  r  r'  r  addTimeoutErrorr   )rF   r  Zcompleted_futuresr   r   r   r   test_zero_timeout  s(    
z"AsCompletedTests.test_zero_timeoutc                 C   s@   | j tjd}dd tt|dD }| t	|d d S )Nr   c                 S   s   g | ]}|qS r   r   )rv   r   r   r   r   rw     s   z;AsCompletedTests.test_duplicate_futures.<locals>.<listcomp>r   r   )
rh   rt   r)   r*   r	   r6  	itertoolsrepeatr   r   )rF   r  r7  r   r   r   test_duplicate_futures  s
    z'AsCompletedTests.test_duplicate_futuresc                 C   s   dd t dD }|ttd |ttdd | tjN tj|ddD ].}|	| t
|}~t  | |  qPW d    n1 s0    Y  |d d	 t|D ]@}|	| t
|}~t  | |  |r|d d	 qd S )
Nc                 S   s   g | ]
}t  qS r   )r   ru   r   r   r   rw     r   zGAsCompletedTests.test_free_reference_yielded_future.<locals>.<listcomp>   r   r    r!   r   r9  test)rx   r   r   r   r   r   r	   r;  r6  removeweakrefrefr   r   r   
set_result)rF   futures_listr   wrr   r   r   "test_free_reference_yielded_future  s&    

,

z3AsCompletedTests.test_free_reference_yielded_futurec                 C   s`   t tttg}| tj"}ttj|dd W d    n1 s@0    Y  | 	t
|jd d S )Nr   r9  z2 (of 4) futures unfinished)r  PENDING_FUTURERUNNING_FUTUREr  r   r	   r;  r   r6  r   strr   )rF   rF  r   r   r   r   "test_correct_timeout_exception_msg  s    0z3AsCompletedTests.test_correct_timeout_exception_msgN)rH   rI   rJ   r8  r<  r?  rH  rL  r   r   r   r   r5    s
   
r5  c                   @   sZ   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Ze	j
dd Zdd Zdd ZdS )ExecutorTestc                 C   s$   | j tdd}| d|  d S )Nr   r@     )rh   rt   r   r   r   rF   r   r   r   r   test_submit  s    zExecutorTest.test_submitc                 C   s   | j jtddd}| d|  | j jtdddd}| | ddddf | t  | j jtdd	 W d    n1 s0    Y  | t | j jdd
 W d    n1 s0    Y  d S )Nr   r@  )r$      r   r   )rF   fn)r   )rR  arg)rS  )rh   rt   r%   r   r   r(   r   	TypeErrorrO  r   r   r   test_submit_keyword  s    .z ExecutorTest.test_submit_keywordc              	   C   sx   |  t| jttdtdttttdtd |  t| jjttdtdddttttdtd d S )N
   r   	chunksize)r   r   rh   r   r   rx   rE   r   r   r   test_map!  s    zExecutorTest.test_mapc                 C   sJ   | j tg dg d}| | d | | d | t|j d S )N)r   r   r   r   )r   r   r   r\   )r   r   )rh   r   r$  r   __next__r   ZeroDivisionError)rF   r   r   r   r   test_map_exception*  s    zExecutorTest.test_map_exceptionc                 C   sd   g }z,| j jtjg dddD ]}|| qW n tjyD   Y n0 | d | d d g| d S )N)r   r   r*  r\   r9  zexpected TimeoutError)	rh   r   r)   r*   r   r	   r;  r   r   )rF   resultsr   r   r   r   test_map_timeout0  s    


zExecutorTest.test_map_timeoutc                 C   s(   | j tdg| jd   | j   d S )Nr   r   )rh   r   rK  rf   rp   rE   r   r   r   test_shutdown_race_issue12456>  s    z*ExecutorTest.test_shutdown_race_issue12456c                    sP   t  }t  t| fdd}| j|j ~ jt	j
d}| |d d S )Nc                    s      S r   )rP   )objZmy_object_collectedr   r   <lambda>L  r   z7ExecutorTest.test_no_stale_references.<locals>.<lambda>r9  z-Stale reference not collected within timeout.)rD   r   rL   rC  rD  rh   rt   rG   rm   r   SHORT_TIMEOUTr   )rF   Z	my_objectZmy_object_callbackZ	collectedr   ra  r   test_no_stale_referencesE  s    z%ExecutorTest.test_no_stale_referencesc              	   C   sF   dD ]<}|  td | j|d W d    q1 s60    Y  qd S )N)r   z"max_workers must be greater than 0r   )assertRaisesRegexr@   re   )rF   Znumberr   r   r   test_max_workers_negativeU  s
    z&ExecutorTest.test_max_workers_negativec                 C   s<   | j ttdD ]$}t|}~t  | |  qd S )NrV  )	rh   r   rS   rx   rC  rD  r   r   r   )rF   r`  rG  r   r   r   test_free_reference\  s
    
z ExecutorTest.test_free_referenceN)rH   rI   rJ   rP  rU  rY  r\  r^  r_  r   Zcpython_onlyrd  rg  rh  r   r   r   r   rM    s   
	
rM  c                   @   sF   e Zd Zdd Zdd Zdd Zdd Zee	e
d	d
dd ZdS )ThreadPoolExecutorTestc                    sD   g   fdd}| j |td | j jdd |  td dS )zTests verifying issue 11777.c                    s     |  d S r   )r   )nr  r   r   record_finishedj  s    zRThreadPoolExecutorTest.test_map_submits_without_iteration.<locals>.record_finishedrV  Trl   N)rh   r   rx   rp   ZassertCountEqual)rF   rl  r   rk  r   "test_map_submits_without_iterationg  s
    z9ThreadPoolExecutorTest.test_map_submits_without_iterationc                 C   s0   |   }tdt pdd }| |j| d S )N    r   r   )re   minos	cpu_countr   _max_workers)rF   rh   Zexpectedr   r   r   test_default_workersq  s    z+ThreadPoolExecutorTest.test_default_workersc                 C   s|   |  d}dd }td}td|j D ]}||| q*| t|j|j td|j D ]}|	  q^|j
dd d S )Nr   c                 S   s   |    d S r   r   r   r   r   r   r   x  s    z<ThreadPoolExecutorTest.test_saturation.<locals>.acquire_lockr      Trl   )re   r   r   rx   rr  rt   r   r   r   r   rp   )rF   rh   r   r   r   r   r   r   test_saturationv  s    


z&ThreadPoolExecutorTest.test_saturationc                 C   s`   |   }|tdd  |tdd  |tdd  | t|jd |jdd	 d S )
Nr  r   r*  r+  r      r   Trl   )re   rt   r%   r   r   r   r   rp   rF   rh   r   r   r   test_idle_thread_reuse  s    z-ThreadPoolExecutorTest.test_idle_thread_reuseregister_at_forkzneed os.register_at_forkc              
      s    fdd t df}| | tdD ]@}t jdtdd}|t W d    q,1 sb0    Y  q,W d    n1 s0    Y  d S )Nc                    s   |   |  d S r   rt   )poolrz  r   r   rt     s    zEThreadPoolExecutorTest.test_hang_global_shutdown_lock.<locals>.submitr   r   r~   )r`   )r	   r|   rt   rx   r   r   tuple)rF   r{  rR   workersr   rz  r   test_hang_global_shutdown_lock  s    z5ThreadPoolExecutorTest.test_hang_global_shutdown_lockN)rH   rI   rJ   rm  rs  ru  rx  r   
skipUnlessrd   rp  r~  r   r   r   r   ri  f  s   
ri  c                   @   st   e Zd Zeejdkddd Zdd Zdd Z	e
d	d
 Zdd Zeddd Zdd Zdd Zdd ZdS )ProcessPoolExecutorTestr   zWindows-only process limitc                 C   s<   |  td tjdd W d    n1 s.0    Y  d S )Nzmax_workers must be <= 61>   r   )rf  r@   r	   r   rE   r   r   r   test_max_workers_too_large  s    z2ProcessPoolExecutorTest.test_max_workers_too_largec                 C   s`   | j tjdg}tt| j j }|  |D ]}| 	t
|j q2| 	t
| j jtdd d S )Nr   r   r@  )rh   rt   r)   r*   nextiterr  r  	terminater   r   r   r   )rF   r	   r  r   r   r   r   test_killed_child  s    z)ProcessPoolExecutorTest.test_killed_childc              	      s    fdd}t tttdtd} t  jjttdtddd|  t  jjttdtddd|  t  jjttdtddd|  t| d S )Nc                      s$   t  jjttdtddd d S )N(   re  rW  )r   rh   r   r   rx   r   rE   r   r   bad_map  s    z;ProcessPoolExecutorTest.test_map_chunksize.<locals>.bad_mapr  r*  rW  r   )r   r   r   rx   r   rh   r   r@   )rF   r  rD  r   rE   r   test_map_chunksize  s    z*ProcessPoolExecutorTest.test_map_chunksizec                 C   s   t dd S )N{   )r   r   r   r   r   _test_traceback  s    z'ProcessPoolExecutorTest._test_tracebackc              	   C   s   | j | j}| t}|  W d    n1 s60    Y  |j}| t|t	 | 
|jd |j}| t|tjj | d|j t :}z|W n  t	y   tjt   Y n0 W d    n1 s0    Y  | d|  d S )N)r  z&raise RuntimeError(123) # some comment)rh   rt   r  r   r+   r   r   ZassertIsr   r   r   r&   	__cause__r	   process_RemoteTracebackr   tbr   captured_stderrr/   
excepthookexc_infogetvalue)rF   r   r   exccausef1r   r   r   test_traceback  s"    &
2z&ProcessPoolExecutorTest.test_tracebackmd5c                 C   s`   t | j }t|}| jt|}|  | |j	j
dd d }t  |  |  d S )Nr   r9  )r   r]   ManagerrK   rh   rt   idr   r   rM   rm   r   r   rp   r   )rF   rN   r`  r   r   r   r   test_ressources_gced_in_workers  s    z7ProcessPoolExecutorTest.test_ressources_gced_in_workersc                 C   s   |  d}t }|d}d|j }zPt|D ]}||j q.| t|j	|j t|D ]}|
  q\W |  n
|  0 d S )Nr   r   rt  )re   r   r   rr  rx   rt   r   r   r   r  r   rp   )rF   rh   r`   r   Z	job_countrR   r   r   r   ru    s    


z'ProcessPoolExecutorTest.test_saturationc                 C   s^   |  d}|tdd  |tdd  |tdd  | t|jd |  d S )	Nr   r  r   r*  r+  r   rv  r   )re   rt   r%   r   r   r   r  rp   rw  r   r   r   test_idle_process_reuse_one  s    
z3ProcessPoolExecutorTest.test_idle_process_reuse_onec                 C   sh   |  d}|tdd  |tdd |tdd  |tdd | t|jd	 |  d S )
Nr      r+  !               r   )re   rt   r%   r   ZassertLessEqualr   r  rp   rw  r   r   r    test_idle_process_reuse_multiple  s    
z8ProcessPoolExecutorTest.test_idle_process_reuse_multipleN)rH   rI   rJ   r   r  r/   r   r  r  r  classmethodr  r  r   Zrequires_hashdigestr  ru  r  r  r   r   r   r   r    s   


r  c                 C   s*   | rt |  ddl}|  |  dS )zInduces a segfault.r   N)r)   r*   faulthandlerdisableZ_sigsegv)delayr  r   r   r   _crash  s
    
r  c                   C   s   t d dS )z#Induces a sys exit with exitcode 1.r   N)r/   exitr   r   r   r   _exit  s    r  c                 C   s
   |  dS )z-Function that raises an Exception in process.Nr   )Errr   r   r   _raise_error  s    r  c                 C   s   ddl }| t_|  dS )z@Function that raises an Exception in process and ignores stderr.r   N)ioStringIOr/   stderr)r  r  r   r   r   _raise_error_ignore_stderr"  s    
r  c                 C   s   |  S )z(Function that returns a instance of cls.r   r  r   r   r   _return_instance)  s    r  c                   @   s   e Zd ZdZdd ZdS )CrashAtPicklez5Bad object that triggers a segfault at pickling time.c                 C   s
   t   d S r   r  rE   r   r   r   
__reduce__0  s    zCrashAtPickle.__reduce__NrH   rI   rJ   __doc__r  r   r   r   r   r  .  s   r  c                   @   s   e Zd ZdZdd ZdS )CrashAtUnpicklez7Bad object that triggers a segfault at unpickling time.c                 C   s   t dfS Nr   r  rE   r   r   r   r  6  s    zCrashAtUnpickle.__reduce__Nr  r   r   r   r   r  4  s   r  c                   @   s   e Zd ZdZdd ZdS )ExitAtPicklez9Bad object that triggers a process exit at pickling time.c                 C   s
   t   d S r   r  rE   r   r   r   r  <  s    zExitAtPickle.__reduce__Nr  r   r   r   r   r  :  s   r  c                   @   s   e Zd ZdZdd ZdS )ExitAtUnpicklez;Bad object that triggers a process exit at unpickling time.c                 C   s   t dfS r  r  rE   r   r   r   r  B  s    zExitAtUnpickle.__reduce__Nr  r   r   r   r   r  @  s   r  c                   @   s   e Zd ZdZdd ZdS )ErrorAtPicklez3Bad object that triggers an error at pickling time.c                 C   s   ddl m} |dd S )Nr   r   zError in pickle)pickler   )rF   r   r   r   r   r  H  s    zErrorAtPickle.__reduce__Nr  r   r   r   r   r  F  s   r  c                   @   s   e Zd ZdZdd ZdS )ErrorAtUnpicklez5Bad object that triggers an error at unpickling time.c                 C   s   ddl m} t|ffS )Nr   )UnpicklingError)r  r  r  )rF   r  r   r   r   r  O  s    zErrorAtUnpickle.__reduce__Nr  r   r   r   r   r  M  s   r  c                   @   s   e Zd ZejZdd ZddddZdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#S )$ExecutorDeadlockTestc                 C   s   dd l }ddlm} |dd.}|j|d |d | }W d    n1 sR0    Y  |j D ]}|  qf|j	dd t
d| tjd | d	|  d S )
Nr   )TemporaryFilezw+)mode)fileTrl   z
Traceback:
 zExecutor deadlock:

)r  tempfiler  Zdump_tracebackseekreadr  r  r  rp   r.   r/   
__stderr__r   )rF   rh   r  r  r   r  r  r   r   r   _fail_on_deadlockW  s    
&
z&ExecutorDeadlockTest._fail_on_deadlockFignore_stderrc             	   G   s   | j jdd | jdt| jd}|j|g|R  }|rBt }nt	 }z`| 
|B | |j| jd W d    n1 s0    Y  W d    n1 s0    Y  W n tjy   | | Y n0 |jdd d S )NTrl   r   r^   r9  )rh   rp   re   r   r]   rt   r   r  r   nullcontextr   r   TIMEOUTr	   r;  r  )rF   errorfuncr  r&   rh   r   r   r   r   r   _check_crashj  s    

Nz!ExecutorDeadlockTest._check_crashc                 C   s   |  ttt  d S r   )r  r   r  r  rE   r   r   r   test_error_at_task_pickle  s    z.ExecutorDeadlockTest.test_error_at_task_picklec                 C   s   |  ttt  d S r   )r  r   r  r  rE   r   r   r   test_exit_at_task_unpickle  s    z/ExecutorDeadlockTest.test_exit_at_task_unpicklec                 C   s   |  ttt  d S r   )r  r   r  r  rE   r   r   r   test_error_at_task_unpickle  s    z0ExecutorDeadlockTest.test_error_at_task_unpicklec                 C   s   |  ttt  d S r   )r  r   r  r  rE   r   r   r   test_crash_at_task_unpickle  s    z0ExecutorDeadlockTest.test_crash_at_task_unpicklec                 C   s   |  tt d S r   )r  r   r  rE   r   r   r   %test_crash_during_func_exec_on_worker  s    z:ExecutorDeadlockTest.test_crash_during_func_exec_on_workerc                 C   s   |  tt d S r   )r  
SystemExitr  rE   r   r   r   $test_exit_during_func_exec_on_worker  s    z9ExecutorDeadlockTest.test_exit_during_func_exec_on_workerc                 C   s   |  ttt d S r   )r  r   r  rE   r   r   r   %test_error_during_func_exec_on_worker  s    z:ExecutorDeadlockTest.test_error_during_func_exec_on_workerc                 C   s   |  ttt d S r   )r  r   r  r  rE   r   r   r   )test_crash_during_result_pickle_on_worker  s    z>ExecutorDeadlockTest.test_crash_during_result_pickle_on_workerc                 C   s   |  ttt d S r   )r  r  r  r  rE   r   r   r   (test_exit_during_result_pickle_on_worker  s    z=ExecutorDeadlockTest.test_exit_during_result_pickle_on_workerc                 C   s   |  ttt d S r   )r  r   r  r  rE   r   r   r   )test_error_during_result_pickle_on_worker  s    z>ExecutorDeadlockTest.test_error_during_result_pickle_on_workerc                 C   s   | j tttdd d S )NTr  )r  r   r  r  rE   r   r   r   3test_error_during_result_unpickle_in_result_handler  s    zHExecutorDeadlockTest.test_error_during_result_unpickle_in_result_handlerc                 C   s   |  ttt d S r   )r  r   r  r  rE   r   r   r   2test_exit_during_result_unpickle_in_result_handler  s    zGExecutorDeadlockTest.test_exit_during_result_unpickle_in_result_handlerc              	   C   s   | j jdd | jdt| jdb}|| _ |jtdd}|jdd | t |	  W d    n1 sl0    Y  W d    n1 s0    Y  d S )NTrl   r   r^   r:   )r  )
rh   rp   re   r   r]   rt   r  r   r   r   )rF   rh   r   r   r   r   test_shutdown_deadlock  s    z+ExecutorDeadlockTest.test_shutdown_deadlockc              	   C   s   | j jdd | jdt| jdx}|| _ |td  |j}|tt	 }|jdd | 
t |  W d    n1 s0    Y  W d    n1 s0    Y  |  d S )NTrl   r   r^   r    F)rh   rp   re   r   r]   rt   r  r   r	  r  r   r   r   )rF   rh   Zexecutor_managerr   r   r   r   test_shutdown_deadlock_pickle  s    Dz2ExecutorDeadlockTest.test_shutdown_deadlock_pickleN)rH   rI   rJ   r   rc  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r  T  s"   r  c                   @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)S )*FutureTestsc                    s:   d   fdd}t  }|| |d | d  d S )Nc                    s   |    d S r   r   Zcallback_futureZcallback_resultr   r   rR    s    z6FutureTests.test_done_callback_with_result.<locals>.fnr\   )r   add_done_callbackrE  r   rF   rR  r   r   r  r   test_done_callback_with_result  s    

z*FutureTests.test_done_callback_with_resultc                    s@   d   fdd}t  }|| |td | d j d S )Nc                    s   |    d S r   r   r  Zcallback_exceptionr   r   rR    s    z9FutureTests.test_done_callback_with_exception.<locals>.fnrA  rA  )r   r  set_exceptionr+   r   r&   r  r   r  r   !test_done_callback_with_exception  s    
z-FutureTests.test_done_callback_with_exceptionc                    s<   d   fdd}t  }|| | |  |   d S )Nc                    s   |    d S r   r   r  Zwas_cancelledr   r   rR    s    z6FutureTests.test_done_callback_with_cancel.<locals>.fn)r   r  r   cancelr  r   r  r   test_done_callback_with_cancel  s    
z*FutureTests.test_done_callback_with_cancelc                    s   t  x}dd fdd} fdd}t }|| || |d |  |   | d|  W d    n1 s0    Y  d S )NFc                    s   d t dd S )NTdoh!r+   r  )raising_was_calledr   r   
raising_fn  s    z9FutureTests.test_done_callback_raises.<locals>.raising_fnc                    s   d d S )NTr   r  )fn_was_calledr   r   rR    s    z1FutureTests.test_done_callback_raises.<locals>.fnr\   zException: doh!)r   r  r   r  rE  r   r   r  )rF   r  r  rR  r   r   )r  r  r   test_done_callback_raises  s    





z%FutureTests.test_done_callback_raisesc                    s:   d   fdd}t  }|d || | d  d S )Nc                    s   |    d S r   r  r  r  r   r   rR     s    z=FutureTests.test_done_callback_already_successful.<locals>.fnr\   )r   rE  r  r   r  r   r  r   %test_done_callback_already_successful  s    

z1FutureTests.test_done_callback_already_successfulc                    s@   d   fdd}t  }|td || | d j d S )Nc                    s   |    d S r   r  r  r  r   r   rR  +  s    z9FutureTests.test_done_callback_already_failed.<locals>.fnrA  r  )r   r  r+   r  r   r&   r  r   r  r   !test_done_callback_already_failed)  s    
z-FutureTests.test_done_callback_already_failedc                    s<   d   fdd}t  }| |  || |   d S )Nc                    s   |    d S r   r   r  r  r   r   rR  6  s    z<FutureTests.test_done_callback_already_cancelled.<locals>.fn)r   r   r  r  r  r   r  r   $test_done_callback_already_cancelled4  s    
z0FutureTests.test_done_callback_already_cancelledc                 C   sn   t  R}dd }t }|d || | d|  | d|  W d    n1 s`0    Y  d S )Nc                 S   s   t dd S )Nr  r  r  r   r   r   r  A  s    zKFutureTests.test_done_callback_raises_already_succeeded.<locals>.raising_fnr\   zexception calling callback forr  )r   r  r   rE  r  r   r  )rF   r  r  r   r   r   r   +test_done_callback_raises_already_succeeded?  s    


z7FutureTests.test_done_callback_raises_already_succeededc                 C   sd   |  ttd |  ttd |  ttd |  ttd |  ttd |  ttd d S )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   reprrI  rJ  r  r  r'  r  rE   r   r   r   	test_reprO  s(    



zFutureTests.test_reprc                 C   s   t td}t td}t td}t td}t tt d}t tdd}| |  | 	|j
t | |  | 	|j
t | |  | 	|j
t | |  | 	|j
t | |  | 	|j
t | |  | 	|j
t d S )Nr   r   r\   r!   )r   r
   r   r   r   r   OSErrorr   r  r   r   r   )rF   r  f2Zf3Zf4Zf5Zf6r   r   r   test_cancel`  s$    



zFutureTests.test_cancelc                 C   sX   |  t  |  t  | t  | t  |  t  |  t  d S r   )	r   rI  r   rJ  r   r  r  r'  r  rE   r   r   r   test_cancelledz  s    zFutureTests.test_cancelledc                 C   sX   |  t  |  t  | t  | t  | t  | t  d S r   )	r   rI  r   rJ  r   r  r  r'  r  rE   r   r   r   	test_done  s    zFutureTests.test_donec                 C   sX   |  t  | t  |  t  |  t  |  t  |  t  d S r   )	r   rI  runningr   rJ  r  r  r'  r  rE   r   r   r   test_running  s    zFutureTests.test_runningc                 C   sz   | j tjtjdd | j tjtjdd | j tjtjdd | j tjtjdd | j t	t
jdd | tjddd d S )Nr   r9  r    )r   r	   r;  rI  r   rJ  CancelledErrorr  r  r  r'  r   r  rE   r   r   r   test_result_with_timeout  s    z$FutureTests.test_result_with_timeoutc                    sJ    fdd}t td tj|d}|  |  jddd |  d S )Nc                      s   t d  d d S )Nr   r    )r)   r*   rE  r   r  r   r   notification  s    
z:FutureTests.test_result_with_success.<locals>.notificationr   targetr\   r9  r    )r   r
   r   Threadstartr   r   r   rF   r  r,   r   r  r   test_result_with_success  s    
z$FutureTests.test_result_with_successc                    sL    fdd}t td tj|d}|  | jtj jt	j
d |  d S )Nc                      s   t d    d S Nr   )r)   r*   r  r   r  r   r   r    s    
z9FutureTests.test_result_with_cancel.<locals>.notificationr   r  r9  )r   r
   r   r  r	  r   r	   r  r   r   rc  r   r
  r   r  r   test_result_with_cancel  s    
z#FutureTests.test_result_with_cancelc                 C   s   | j tjtjdd | j tjtjdd | j tjtjdd | j tjtjdd | 	t
tjddt | tjddd  d S )Nr   r9  )r   r	   r;  rI  r   rJ  r  r  r  r   
isinstancer'  r  r   r  rE   r   r   r   test_exception_with_timeout  s     z'FutureTests.test_exception_with_timeoutc                    sP    fdd}t td tj|d}|  | t jtj	dt
 |  d S )Nc                      sL   t d  j( t _t  _ j  W d    n1 s>0    Y  d S r  )r)   r*   
_conditionr   r   r  r   
notify_allr   r  r   r   r    s
    
z=FutureTests.test_exception_with_success.<locals>.notificationr   r  r9  )r   r
   r   r  r	  r   r  r   r   rc  r  r   r
  r   r  r   test_exception_with_success  s    
z'FutureTests.test_exception_with_successc                 C   sn   t td}|d | tjd |d W d    n1 sB0    Y  | |  | |	 d d S )Nr   r   z=FINISHED: <Future at 0x[0-9a-f]+ state=finished returned int>r   )
r   r
   rE  rf  r	   InvalidStateErrorr   r   r   r   )rF   r   r   r   r   test_multiple_set_result  s    

(z$FutureTests.test_multiple_set_resultc                 C   sh   t td}t }|| | tjd |t  W d    n1 sJ0    Y  | |	 | d S )Nr   zBFINISHED: <Future at 0x[0-9a-f]+ state=finished raised ValueError>)
r   r
   r@   r  rf  r	   r  r+   r   r   )rF   r   r   r   r   r   test_multiple_set_exception  s    

*z'FutureTests.test_multiple_set_exceptionN)rH   rI   rJ   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r    s(   r  c                  C   s.   t tjj t } t jtjg| R   d S r   )r   ZaddModuleCleanupmultiprocessingutil_cleanup_testsr   rU   rY   )thread_infor   r   r   setUpModule  s    r  __main__)N)N)]rA  r   import_moduleZ*skip_if_broken_multiprocessing_synchronizeZtest.supportr   Ztest.support.script_helperr   r   r=  r;   Zlogging.handlersr   rp  r   r/   r   r)   r   rC  r  r   
concurrentr	   concurrent.futures._baser
   r   r   r   r   r   r   Zconcurrent.futures.processr   r  r   Zmultiprocessing.processZmultiprocessing.utilr   rI  rJ  r  r  r  r'  r  r5   r%   r(   r-   r3   r6   r7   rC   objectrD   rK   rS   ZTestCaserT   r[   r{   r}   r   r   r   r   r   r   r   r  r  r.  r5  rM  ri  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rH   mainr   r   r   r   <module>   s   
$





	*


;kaImRV4p
	   
