a 4dgC@s ddlmZededdlmZddlmZddlZddl Z ddl Z ddl m Z ddl Z ddlZddlZddlZddlZddlZddlZddlmZddlmZdd lmZmZmZmZmZmZmZdd l m!Z!dd l"m#Z#ddl$Z"ddl%Z"eddfd d Z&e&edZ'e&edZ(e&edZ)e&edZ*e&ee+dZ,e&eddZ-da.ddZ/ddZ0ddZ1ddZ2ddZ3ddZ4dkdd Z5Gd!d"d"e6Z7Gd#d$d$Z8d%d&Z9Gd'd(d(ej:Z;Gd)d*d*ZGd/d0d0e<Z?Gd1d2d2e<Z@e;fe=e>e@e?ffd3d4ZAGd5d6d6e<ZBGd7d8d8e<ZCeAeBeAeCGd9d:d:ZDGd;d<dd>eDZFeAeFe>e@e?fd?Gd@dAdAZGGdBdCdCe=eGe;ZHeAeGe>e@e?fd?GdDdEdEZIeAeIGdFdGdGZJGdHdIdIe=eJe;ZKGdJdKdKeJZLeAeLe>e@e?fd?dldLdMZMdNdOZNdPdQZOdRdSZPdTdUZQGdVdWdWe6ZRGdXdYdYe6ZSGdZd[d[e6ZTGd\d]d]e6ZUGd^d_d_e6ZVGd`dadae6ZWGdbdcdcZXeAeXe>e@e?fd?Gdddedee;ZYdaZdfdgZ[dhdiZ\e]djkre^dS)m)support_multiprocessing)hashlib_helper)assert_python_okN) QueueHandler PicklingError)futures)PENDINGRUNNING CANCELLEDCANCELLED_AND_NOTIFIEDFINISHEDFutureBrokenExecutor)BrokenProcessPool) get_contextcCst}||_||_||_|SN)r_state _exception_result)state exceptionresultfr8/usr/local/lib/python3.9/test/test_concurrent_futures.py create_future#s rrrr*rr uninitializedcCs||Srr)xyrrrmul5sr%cOs||fSrr)argskwargsrrrcapture8sr(cCst|tddS)Nzthis is an exception)timesleep Exception)trrrsleep_and_raise;s r-cCs t|t|tjdSr)r)r*printsysstdoutflush)r,msgrrrsleep_and_print?s r3cCs|adSrINITIALIZER_STATUS)r#rrrinitDsr6cCstSrr4rrrrget_init_statusHsr7cCsF|dur0td}|t||dd|_tdtddS)Nconcurrent.futuresCRITICALF皙?zerror in initializer) logging getLogger addHandlerrsetLevel propagater)r* ValueError) log_queueloggerrrr init_failKs   rCc@seZdZddZdS)MyObjectcCsdSrrselfrrr my_methodVszMyObject.my_methodN)__name__ __module__ __qualname__rGrrrrrDUsrDc@seZdZddZddZdS) EventfulGCObjcCs||_dSr)Eventevent)rFmgrrrr__init__[szEventfulGCObj.__init__cCs|jdSr)rMsetrErrr__del__^szEventfulGCObj.__del__N)rHrIrJrOrQrrrrrKZsrKcCstSr)rD)_rrrmake_dummy_objectbsrSc@seZdZddZddZdS) BaseTestCasecCst|_dSr)rthreading_setup _thread_keyrErrrsetUpgszBaseTestCase.setUpcCsttj|jdSr)r reap_childrenthreading_cleanuprVrErrrtearDownjszBaseTestCase.tearDownN)rHrIrJrWrZrrrrrTfsrTcs@eZdZdZiZfddZfddZddZdd ZZ S) ExecutorMixincsftt|_t|dr@|jf|j|d|j |_ n|jfd|ji|j |_ | dS)Nctx max_workers mp_contextr_) superrWr) monotonict1hasattr executor_type worker_countrexecutor_kwargsexecutor_prime_executorrE __class__rrrWss    zExecutorMixin.setUpcsT|jjddd|_t|j}tjr8td|dd||ddt dS)NTwaitz%.2fs )endi,z+synchronization issue: test lasted too long) rhshutdownr)rbrcrverboser.Z assertLessrarZ)rFZdtrjrrrZszExecutorMixin.tearDowncCs t|jSr)rr]rErrrrszExecutorMixin.get_contextcs.fddtjD}|D] }|qdS)Ncsg|]}jtjdqSr:rhsubmitr)r*.0rRrErr sz1ExecutorMixin._prime_executor..)rangerfrrFr rrrErris  zExecutorMixin._prime_executor) rHrIrJrfrgrWrZrri __classcell__rrrjrr[os   r[c@seZdZejZdS)ThreadPoolMixinN)rHrIrJr ThreadPoolExecutorrerrrrr{sr{cs&eZdZejZdZfddZZS)ProcessPoolForkMixinforkcstjdkr|dtSNwin32zrequire unix systemr/platformZskipTestrarrErjrrrs  z ProcessPoolForkMixin.get_context rHrIrJr ProcessPoolExecutorrer]rrzrrrjrr}sr}c@seZdZejZdZdS)ProcessPoolSpawnMixinspawnN)rHrIrJr rrer]rrrrrsrcs&eZdZejZdZfddZZS)ProcessPoolForkserverMixin forkservercstjdkr|dtSrrrErjrrrs  z&ProcessPoolForkserverMixin.get_contextrrrrjrrsrcCsPdd}|D]>}d||j||jf}t||f|f|i}|t|<q dS)NcSs4|dr|ddS|dr,|ddS|SdS)N)ZMixinZTestsZTest)endswith)namerrr strip_mixins     z*create_executor_tests..strip_mixinz%s%sTest)rHtypeglobals)Zmixinbasesexecutor_mixinsrZexerclsrrrcreate_executor_testssrcs(eZdZdZfddZddZZS)InitializerMixincs dattdd|_tdS)Nr") initialized initializerinitargs)r5dictr6rgrarWrErjrrrWs zInitializerMixin.setUpcs6fddtjD}|D]}|dqdS)Ncsg|]}jtqSr)rhrtr7rurErrrwsz5InitializerMixin.test_initializer..r)rxrf assertEqualrryrrErtest_initializers  z!InitializerMixin.test_initializer)rHrIrJrfrWrrzrrrjrrs rcs>eZdZdZfddZddZddZejdd Z Z S) FailingInitializerMixinrcsZt|dr4||_|j|_tt|jfd|_nd|_d|_ttd|_t dS)Nr]r)r) rdrr`QueuerArrCrgrarWrErjrrrWs     zFailingInitializerMixin.setUpc Cs|dz|jt}Wnty.Yn40|t|Wdn1sX0Yt}|jj st|dkr| dt dqj|t|jtWdn1s0YWdn1s0YdS)Nz ValueError: error in initializerr\zexecutor not broken after 5 s.g{Gz?) _assert_loggedrhrtr7r assertRaisesrr)rb_brokenfailr*)rFfuturercrrrrs   &   z(FailingInitializerMixin.test_initializercCsdSrrrErrrrisz'FailingInitializerMixin._prime_executorc#s|jdurFdVg}z||jqWq~tjyBYq~0n8|dd}dVWdn1sn0Y|j}|t fdd|D|dS)Nr8r9c3s|]}|vVqdSrr)rvliner2rr z9FailingInitializerMixin._assert_logged..) rAappend get_nowait getMessagequeueEmptyZ assertLogsoutput assertTrueany)rFr2rcmrrrrs $z&FailingInitializerMixin._assert_logged) rHrIrJrfrWrri contextlibcontextmanagerrrzrrrjrrs  rc@s<eZdZddZddZddZddZd d Zd d Zd S)ExecutorShutdownTestcCs$|j|t|jjtdddS)Nrr\)rhrpr RuntimeErrorrtpowrErrrtest_run_after_shutdowns  z,ExecutorShutdownTest.test_run_after_shutdowncCsDtddj|jjt|ddd\}}}||||ddS)N-caKif 1: from concurrent.futures import {executor_type} from time import sleep from test.test_concurrent_futures import sleep_and_print if __name__ == "__main__": context = '{context}' if context == "": t = {executor_type}(5) else: from multiprocessing import get_context context = get_context(context) t = {executor_type}(5, mp_context=context) t.submit(sleep_and_print, 1.0, "apple") r]recontextapple)rformatrerHgetattr assertFalserstriprFrcouterrrrrtest_interpreter_shutdown"s    z.ExecutorShutdownTest.test_interpreter_shutdowncCsJtddj|jjt|ddd\}}}|d|||ddS)Nraif 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]rrz)RuntimeError: cannot schedule new futuress runtime-error) rrrerHrassertIndecoderrrrrr&test_submit_after_interpreter_shutdown8s  z;ExecutorShutdownTest.test_submit_after_interpreter_shutdowncs6fddtdD}j|D] }|q$dS)Ncsg|]}jtjdqSrrrsrurErrrwUrz=ExecutorShutdownTest.test_hang_issue12364..2)rxrhrpr)rFfsrrrErtest_hang_issue12364Ts z)ExecutorShutdownTest.test_hang_issue12364cs|jddfddtdD}jdddd|D}|jt|d kd t|d d d|D}|D],}|j|d |jd ||qn|jt|dkdt|d dS)Nr_csg|]}tjdqSrr)rtr)r*rurhrrrw\rz.rT)cancel_futurescSsg|]}|r|qSr cancelledrvfutrrrrwar#zlen(cancelled)=rcSsg|]}|s|qSrrrrrrrwgrz fut._state=rz len(others)=) rerxrprlendoner assertIsNoner)rFrrZothersrrrrtest_cancel_futuresZs   z(ExecutorShutdownTest.test_cancel_futurescCsP|jtjkrtdtddj|jjd\}}}||| | ddS)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/issue39205raNif 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) rerN) rer runittestZSkipTestrrrHrrrrrrrtest_hang_issue39205qs  z)ExecutorShutdownTest.test_hang_issue39205N) rHrIrJrrrrrrrrrrrs rc@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)ThreadPoolShutdownTestcCsdSrrrErrrrisz&ThreadPoolShutdownTest._prime_executorcCs|dd}td}tdD]}|j||q|t|jjdtdD] }|qJ|j |jjD] }| qjdS)NcSs |dSracquirelockrrr acquire_lockszCThreadPoolShutdownTest.test_threads_terminate..acquire_lockrr) threading Semaphorerxrhrtrr_threadsreleaserpjoin)rFrsemir,rrrtest_threads_terminates      z-ThreadPoolShutdownTest.test_threads_terminatec Csjtjdd6}|}|t|ttddgdWdn1sH0Y|jD] }|qXdSNr\rr) r\rrrrrrr) r r|rlistmapabsrxrr)rFerhr,rrrtest_context_manager_shutdowns" z4ThreadPoolShutdownTest.test_context_manager_shutdowncCs^tjdd}|ttdd}|j}~|D] }|q*tddt|tddDsZJdS)Nr\rrcSsg|]\}}|t|kqSrrrvrvrrrrwrz.) r r|rrrxrrallziprFrhresthreadsr,rrrtest_del_shutdowns  z(ThreadPoolShutdownTest.test_del_shutdowncCshtjdd}|ttdd}|j}|jdd|D] }|q4tddt |tddDsdJdS)Nr\rrFrlcSsg|]\}}|t|kqSrrrrrrrwrz@ThreadPoolShutdownTest.test_shutdown_no_wait..) r r|rrrxrrprrrrrrrtest_shutdown_no_waits   z,ThreadPoolShutdownTest.test_shutdown_no_waitcCsLtjddd}|ttdd|j}~|D]}||jd|q,dS)Nr\Z SpecialPool)r_Zthread_name_prefixrz^SpecialPool_[0-4]$ r r|rrrxr assertRegexrrrFrhrr,rrrtest_thread_names_assignedsz1ThreadPoolShutdownTest.test_thread_names_assignedcCsJtjdd}|ttdd|j}~|D]}||jd|q*dS)Nr\rrzThreadPoolExecutor-\d+_[0-4]$rrrrrtest_thread_names_defaults z0ThreadPoolShutdownTest.test_thread_names_defaultcCs:tddj|jjd\}}}||||ddS)Nra[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) rr)rrrerHrrrrrrrtest_cancel_futures_wait_falses  z5ThreadPoolShutdownTest.test_cancel_futures_wait_falseN) rHrIrJrirrrrrrrrrrrrs    rc@s4eZdZddZddZddZddZd d Zd S) ProcessPoolShutdownTestcCsdSrrrErrrrisz'ProcessPoolShutdownTest._prime_executorcCsdd}t}|d}tdD]}|j||q |t|jjdtdD] }|qP|jj}|j | D] }| qxdS)NcSs |dSrrrrrrrszFProcessPoolShutdownTest.test_processes_terminate..acquire_lockrr) rrrxrhrtrr _processesrrpvaluesr)rFrr`rrR processesprrrtest_processes_terminates      z0ProcessPoolShutdownTest.test_processes_terminatec Csntjdd8}|j}|t|ttddgdWdn1sJ0Y|D] }| q\dSr) r rrrrrrrxrr)rFrrrrrrrs" z5ProcessPoolShutdownTest.test_context_manager_shutdowncCstjdd}|ttdd}|j}|j}|j}|j}~|| D] }|qH| t ddt |tddDsJdS)Nr\rrcSsg|]\}}|t|kqSrrrrrrrwrz=ProcessPoolShutdownTest.test_del_shutdown..) r rrrrx_executor_manager_threadr _call_queuerr join_threadrr)rFrhrexecutor_manager_threadr call_queuerrrrrs   z)ProcessPoolShutdownTest.test_del_shutdowncCstjdd}|ttdd}|j}|j}|j}|jdd| | D] }| qL| t ddt |tddDsJdS)Nr\rrFrlcSsg|]\}}|t|kqSrrrrrrrw*rzAProcessPoolShutdownTest.test_shutdown_no_wait..)r rrrrxrr rrprrr rr)rFrhrrr r rrrrrs    z-ProcessPoolShutdownTest.test_shutdown_no_waitN)rHrIrJrirrrrrrrrrs  r)rc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS) WaitTestscCsd|jtdd}|jtjd}tjt||gtjd\}}| t |g|| t t|g|dS)Nr? return_when) rhrtr%r)r*r rmCANCELLED_FUTUREFIRST_COMPLETEDrrP)rFfuture1future2rnot_donerrrtest_first_completed5s zWaitTests.test_first_completedcCsT|jtjd}tjtt|gtjd\}}| t ttg|| t |g|dS)Nrr) rhrtr)r*r rmCANCELLED_AND_NOTIFIED_FUTURESUCCESSFUL_FUTURErrrPrFrfinishedpendingrrr+test_first_completed_some_already_completed@s  z5WaitTests.test_first_completed_some_already_completedcCsr|jtdd}|jtd}|jtjd}tj|||gtjd\}}| t ||g|| t |g|dS)Nrrrrr) rhrtr%r-r)r*r rmFIRST_EXCEPTIONrrP)rFrrZfuture3rrrrrtest_first_exceptionLs zWaitTests.test_first_exceptioncCsl|jtdd}|jtjd}tjttt ||gtj d\}}| t tt |g|| t t|g|dS)Nrrrr) rhrtdivmodr)r*r rmrrrrrrPrFrrrrrrr*test_first_exception_some_already_completeXs" z4WaitTests.test_first_exception_some_already_completecCsP|jtjd}tjt|gtjd\}}|t tg||t |g|dS)Nrr) rhrtr)r*r rmEXCEPTION_FUTURErrrPrrrr'test_first_exception_one_already_failedhs z1WaitTests.test_first_exception_one_already_failedcCsj|jtdd}|jtdd}tjttt||gtj d\}}| t ttt||g|| t |dS)Nrrrr) rhrtr r%r rmrrr# ALL_COMPLETEDrrPr!rrrtest_all_completedrs( zWaitTests.test_all_completedcCsn|jtdd}|jtjd}tjttt ||gdtj d\}}| t ttt |g|| t |g|dS)Nr\)timeoutr) rhrtr%r)r*r rmrr#rr%rrPr!rrr test_timeouts& zWaitTests.test_timeoutN) rHrIrJrrrr"r$r&r*rrrrr 3s    r c@seZdZddZdS)ThreadPoolWaitTestsc svtfddt}tdz>fddtdD}tj|tj dWt|n t|0dS)Ncs dSrrlr)rMrr future_funcsz@ThreadPoolWaitTests.test_pending_calls_race..future_funcgư>csh|]}jqSr)rhrt)rvr)r,rFrr rz>ThreadPoolWaitTests.test_pending_calls_race..dr) rrLr/getswitchintervalsetswitchintervalrxrPr rmr%)rFZoldswitchintervalrr)rMr,rFrtest_pending_calls_races  z+ThreadPoolWaitTests.test_pending_calls_raceN)rHrIrJr1rrrrr+sr+c@s4eZdZddZddZddZddZd d Zd S) AsCompletedTestscCsV|jtdd}|jtdd}ttttt||g}| tttt||g|dS)Nrrr(r') rhrtr%rPr as_completedrr#rr)rFrr completedrrrtest_no_timeouts$z AsCompletedTests.test_no_timeoutcCsp|jtjd}t}z*tjttt |gddD]}| |q.Wntj yTYn0| tttt g|dS)Nrrr)) rhrtr)r*rPr r3rr#radd TimeoutErrorr)rFrZcompleted_futuresrrrrtest_zero_timeouts( z"AsCompletedTests.test_zero_timeoutcCs@|jtjd}ddtt|dD}|t |ddS)NrcSsg|]}|qSrr)rvrrrrrwsz;AsCompletedTests.test_duplicate_futures..rr) rhrtr)r*r r3 itertoolsrepeatrr)rFrr4rrrtest_duplicate_futuress z'AsCompletedTests.test_duplicate_futurescCsddtdD}|ttd|ttdd|tjFtj|ddD]&}| |t |}~| |qPWdn1s0Y|d d t|D]8}| |t |}~| ||r|d d qdS) NcSsg|] }tqSr)rrurrrrwrzGAsCompletedTests.test_free_reference_yielded_future..rr r!rr6test)rxrrr rrr r8r3removeweakrefrefr set_result)rF futures_listrwrrrr"test_free_reference_yielded_futures"  ,   z3AsCompletedTests.test_free_reference_yielded_futurecCs`ttttg}|tj"}ttj|ddWdn1s@0Y| t |j ddS)Nrr6z2 (of 4) futures unfinished) rPENDING_FUTURERUNNING_FUTURErrr r8rr3rstrr)rFrCrrrr"test_correct_timeout_exception_msgs 0z3AsCompletedTests.test_correct_timeout_exception_msgN)rHrIrJr5r9r<rErIrrrrr2s  r2c@sZeZdZddZddZddZddZd d Zd d Ze j d dZ ddZ ddZ dS) ExecutorTestcCs$|jtdd}|d|dS)Nrr=)rhrtrrrrFrrrr test_submitszExecutorTest.test_submitcCs|jjtddd}|d||jjtdddd}||ddddf|t |jjtdd Wdn1s0Y|t|jjdd Wdn1s0YdS) Nrr=)r$rr)rFfn)r)rOarg)rP)rhrtr%rrr(r TypeErrorrLrrrtest_submit_keyword s . z ExecutorTest.test_submit_keywordc Csx|t|jttdtdttttdtd|t|jjttdtdddttttdtddS)N r chunksize)rrrhrrrxrErrrtest_mapszExecutorTest.test_mapcCsJ|jtgdgd}||d||d|t|jdS)N)rrrr)rrrr\)rr)rhrr r__next__rZeroDivisionError)rFrrrrtest_map_exceptionszExecutorTest.test_map_exceptioncCsdg}z,|jjtjgdddD]}||qWntjyDYn 0|d|ddg|dS)N)rrr'r\r6zexpected TimeoutError) rhrr)r*rr r8rr)rFresultsrrrrtest_map_timeout#s   zExecutorTest.test_map_timeoutcCs(|jtdg|jd|jdS)Nrr)rhrrHrfrprErrrtest_shutdown_race_issue124561sz*ExecutorTest.test_shutdown_race_issue12456csPt}tt|fdd}|j|j~jt j d}| |ddS)NcsSr)rP)objZmy_object_collectedrr?rz7ExecutorTest.test_no_stale_references..r6z-Stale reference not collected within timeout.) rDrrLr@rArhrtrGrmr SHORT_TIMEOUTr)rFZ my_objectZmy_object_callbackZ collectedrr^rtest_no_stale_references8s z%ExecutorTest.test_no_stale_referencesc CsFdD]<}|td|j|dWdq1s60YqdS)N)rz"max_workers must be greater than 0r)assertRaisesRegexr@re)rFZnumberrrrtest_max_workers_negativeHs z&ExecutorTest.test_max_workers_negativecCs4|jttdD]}t|}~||qdS)NrS)rhrrSrxr@rAr)rFr]rDrrrtest_free_referenceOs z ExecutorTest.test_free_referenceN)rHrIrJrMrRrVrYr[r\rZ cpython_onlyrardrerrrrrJs   rJc@s,eZdZddZddZddZddZd S) ThreadPoolExecutorTestcsDgfdd}|j|td|jjdd|tddS)zTests verifying issue 11777.cs|dSr)r)nrrrrecord_finished\szRThreadPoolExecutorTest.test_map_submits_without_iteration..record_finishedrSTrlN)rhrrxrpZassertCountEqual)rFrirrhr"test_map_submits_without_iterationYs  z9ThreadPoolExecutorTest.test_map_submits_without_iterationcCs0|}tdtpdd}||j|dS)N rr)reminos cpu_countr _max_workers)rFrhZexpectedrrrtest_default_workerscsz+ThreadPoolExecutorTest.test_default_workerscCs||d}dd}td}td|jD]}|||q*|t|j|jtd|jD] }| q^|j dddS)NrcSs |dSrrrrrrrjsz.acquire_lockrTrl) rerrrxrortrrrrrp)rFrhrrrrrrtest_saturationhs   z&ThreadPoolExecutorTest.test_saturationcCs`|}|tdd|tdd|tdd|t|jd|jdd dS) Nrrr'r(rrTrl)rertr%rrrrrprFrhrrrtest_idle_thread_reuseus z-ThreadPoolExecutorTest.test_idle_thread_reuseN)rHrIrJrjrprrrurrrrrfXs  rfc@steZdZeejdkdddZddZddZ e d d Z d d Z e d ddZddZddZddZdS)ProcessPoolExecutorTestrzWindows-only process limitcCs<|tdtjddWdn1s.0YdS)Nzmax_workers must be <= 61>r)rcr@r rrErrrtest_max_workers_too_largesz2ProcessPoolExecutorTest.test_max_workers_too_largecCs`|jtjdg}tt|jj}||D]}| t |j q2| t |jjt dddS)Nrrr=) rhrtr)r*nextiterrr terminaterrrr)rFr rrrrrtest_killed_childs z)ProcessPoolExecutorTest.test_killed_childc sfdd}ttttdtd}tjjttdtddd|tjjttdtddd|tjjttdtddd|t|dS)Ncs$tjjttdtddddS)N(rbrT)rrhrrrxrrErrbad_mapsz;ProcessPoolExecutorTest.test_map_chunksize..bad_mapr}r'rTr)rrrrxrrhrr@)rFr~rArrErtest_map_chunksizes z*ProcessPoolExecutorTest.test_map_chunksizecCs tddS)N{)rrrrr_test_tracebacksz'ProcessPoolExecutorTest._test_tracebackc Cs|j|j}|t}|Wdn1s60Y|j}|t|t | |j d|j }|t|t jj|d|jt:}z|Wn t ytjtYn0Wdn1s0Y|d|dS)N)rz&raise RuntimeError(123) # some comment)rhrtrrr+rrZassertIsrrrr& __cause__r process_RemoteTracebackrtbrcaptured_stderrr/ excepthookexc_infogetvalue)rFrrexccausef1rrrtest_tracebacks" &  2z&ProcessPoolExecutorTest.test_tracebackmd5cCs`t|j}t|}|jt|}|||j j ddd}t | |dS)Nrr6)rr]ManagerrKrhrtidrrrMrmr gc_collectrpr)rFrNr]rrrrtest_ressources_gced_in_workerssz7ProcessPoolExecutorTest.test_ressources_gced_in_workerscCs|d}t}|d}d|j}zPt|D]}||jq.|t|j |jt|D] }| q\W| n | 0dS)Nrrrq) rerrrorxrtrrrrrrp)rFrhr`rZ job_countrRrrrrrs      z'ProcessPoolExecutorTest.test_saturationcCs^|d}|tdd|tdd|tdd|t|jd|dS) Nrrrr'r(rrsr)rertr%rrrrrprtrrrtest_idle_process_reuse_ones  z3ProcessPoolExecutorTest.test_idle_process_reuse_onecCsh|d}|tdd|tdd|tdd|tdd|t|jd |dS) Nr r(!r)rertr%rZassertLessEqualrrrprtrrr test_idle_process_reuse_multiples z8ProcessPoolExecutorTest.test_idle_process_reuse_multipleN)rHrIrJrZ skipUnlessr/rrxr|r classmethodrrrZrequires_hashdigestrrrrrrrrrrv~s    rvcCs*|rt|ddl}||dS)zInduces a segfault.rN)r)r* faulthandlerdisableZ_sigsegv)delayrrrr_crashs  rcCstddS)z#Induces a sys exit with exitcode 1.rN)r/exitrrrr_exitsrcCs |dS)z-Function that raises an Exception in process.Nr)Errrrr _raise_errorsrcCsddl}|t_|dS)z@Function that raises an Exception in process and ignores stderr.rN)ioStringIOr/stderr)rrrrr_raise_error_ignore_stderrs rcCs|S)z(Function that returns a instance of cls.rrrrr_return_instance src@seZdZdZddZdS) CrashAtPicklez5Bad object that triggers a segfault at pickling time.cCs tdSrrrErrr __reduce__szCrashAtPickle.__reduce__NrHrIrJ__doc__rrrrrrsrc@seZdZdZddZdS)CrashAtUnpicklez7Bad object that triggers a segfault at unpickling time.cCstdfSNrrrErrrrszCrashAtUnpickle.__reduce__Nrrrrrrsrc@seZdZdZddZdS) ExitAtPicklez9Bad object that triggers a process exit at pickling time.cCs tdSrrrErrrr szExitAtPickle.__reduce__Nrrrrrrsrc@seZdZdZddZdS)ExitAtUnpicklez;Bad object that triggers a process exit at unpickling time.cCstdfSrrrErrrr&szExitAtUnpickle.__reduce__Nrrrrrr$src@seZdZdZddZdS) ErrorAtPicklez3Bad object that triggers an error at pickling time.cCsddlm}|ddS)NrrzError in pickle)pickler)rFrrrrr,s zErrorAtPickle.__reduce__Nrrrrrr*src@seZdZdZddZdS)ErrorAtUnpicklez5Bad object that triggers an error at unpickling time.cCsddlm}t|ffS)Nr)UnpicklingError)rrr)rFrrrrr3s zErrorAtUnpickle.__reduce__Nrrrrrr1src@seZdZejZddZddddZddZd d Z d d Z d dZ ddZ ddZ ddZddZddZddZddZddZdd Zd!d"Zd#S)$ExecutorDeadlockTestcCsddl}ddlm}|dd.}|j|d|d|}Wdn1sR0Y|jD] }|qf|j ddt d|t j d| d |dS) Nr) TemporaryFilezw+)mode)fileTrlz Traceback: zExecutor deadlock: )rtempfilerZdump_tracebackseekreadrrr{rpr.r/ __stderr__r)rFrhrrrrrrrr_fail_on_deadlock;s    &  z&ExecutorDeadlockTest._fail_on_deadlockF ignore_stderrc Gs|jjdd|jdt|jd}|j|g|R}|rBt}nt }z`| |B||j |j dWdn1s0YWdn1s0YWnt jy||Yn0|jdddS)NTrlrr^r6)rhrprerr]rtrrr nullcontextrrTIMEOUTr r8r)rFerrorfuncrr&rhrrrrr _check_crashNs   Nz!ExecutorDeadlockTest._check_crashcCs|tttdSr)rrrrrErrrtest_error_at_task_pickleesz.ExecutorDeadlockTest.test_error_at_task_picklecCs|tttdSr)rrrrrErrrtest_exit_at_task_unpicklejsz/ExecutorDeadlockTest.test_exit_at_task_unpicklecCs|tttdSr)rrrrrErrrtest_error_at_task_unpicklensz0ExecutorDeadlockTest.test_error_at_task_unpicklecCs|tttdSr)rrrrrErrrtest_crash_at_task_unpicklersz0ExecutorDeadlockTest.test_crash_at_task_unpicklecCs|ttdSr)rrrrErrr%test_crash_during_func_exec_on_workervsz:ExecutorDeadlockTest.test_crash_during_func_exec_on_workercCs|ttdSr)r SystemExitrrErrr$test_exit_during_func_exec_on_workerzsz9ExecutorDeadlockTest.test_exit_during_func_exec_on_workercCs|tttdSr)rrrrErrr%test_error_during_func_exec_on_worker~sz:ExecutorDeadlockTest.test_error_during_func_exec_on_workercCs|tttdSr)rrrrrErrr)test_crash_during_result_pickle_on_workersz>ExecutorDeadlockTest.test_crash_during_result_pickle_on_workercCs|tttdSr)rrrrrErrr(test_exit_during_result_pickle_on_workersz=ExecutorDeadlockTest.test_exit_during_result_pickle_on_workercCs|tttdSr)rrrrrErrr)test_error_during_result_pickle_on_workersz>ExecutorDeadlockTest.test_error_during_result_pickle_on_workercCs|jtttdddS)NTr)rrrrrErrr3test_error_during_result_unpickle_in_result_handlerszHExecutorDeadlockTest.test_error_during_result_unpickle_in_result_handlercCs|tttdSr)rrrrrErrr2test_exit_during_result_unpickle_in_result_handlerszGExecutorDeadlockTest.test_exit_during_result_unpickle_in_result_handlerc Cs|jjdd|jdt|jdb}||_|jtdd}|jdd|t| Wdn1sl0YWdn1s0YdS)NTrlrr^r:)r) rhrprerr]rtrrrr)rFrhrrrrtest_shutdown_deadlocks  z+ExecutorDeadlockTest.test_shutdown_deadlockc Cs|jjdd|jdt|jdx}||_|td|j}|tt }|jdd| t |Wdn1s0YWdn1s0Y| dS)NTrlrr^r F) rhrprerr]rtrrrrrrr)rFrhZexecutor_managerrrrrtest_shutdown_deadlock_pickles  Dz2ExecutorDeadlockTest.test_shutdown_deadlock_pickleN)rHrIrJrr`rrrrrrrrrrrrrrrrrrrrrr8s" rc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)S)* FutureTestscs:dfdd}t}|||d|ddS)Ncs |dSrrZcallback_futureZcallback_resultrrrOsz6FutureTests.test_done_callback_with_result..fnr\)radd_done_callbackrBrrFrOrrrrtest_done_callback_with_results    z*FutureTests.test_done_callback_with_resultcs@dfdd}t}|||td|djdS)Ncs |dSrrrZcallback_exceptionrrrOsz9FutureTests.test_done_callback_with_exception..fnr>r>)rr set_exceptionr+rr&rrrr!test_done_callback_with_exceptions   z-FutureTests.test_done_callback_with_exceptioncs<dfdd}t}|||||dS)Ncs |dSrrrZ was_cancelledrrrOsz6FutureTests.test_done_callback_with_cancel..fn)rrrcancelrrrrtest_done_callback_with_cancels   z*FutureTests.test_done_callback_with_cancelcstx}ddfdd}fdd}t}|||||d|||d|Wdn1s0YdS)NFcsdtddS)NTdoh!r+r)raising_was_calledrr raising_fnsz9FutureTests.test_done_callback_raises..raising_fncsddS)NTrr) fn_was_calledrrrOsz1FutureTests.test_done_callback_raises..fnr\zException: doh!)rrrrrBrrr)rFrrrOrr)rrrtest_done_callback_raisess        z%FutureTests.test_done_callback_raisescs:dfdd}t}|d|||ddS)Ncs |dSrrrrrrrOsz=FutureTests.test_done_callback_already_successful..fnr\)rrBrrrrrr%test_done_callback_already_successfuls    z1FutureTests.test_done_callback_already_successfulcs@dfdd}t}|td|||djdS)Ncs |dSrrrrrrrOsz9FutureTests.test_done_callback_already_failed..fnr>r)rrr+rrr&rrrr!test_done_callback_already_failed s   z-FutureTests.test_done_callback_already_failedcs<dfdd}t}|||||dS)Ncs |dSrrrrrrrOsz.fn)rrrrrrrr$test_done_callback_already_cancelleds   z0FutureTests.test_done_callback_already_cancelledcCsntR}dd}t}|d|||d||d|Wdn1s`0YdS)NcSs tddS)Nrrrrrrr%szKFutureTests.test_done_callback_raises_already_succeeded..raising_fnr\zexception calling callback forr)rrrrBrrr)rFrrrrrr+test_done_callback_raises_already_succeeded#s   z7FutureTests.test_done_callback_raises_already_succeededcCsd|ttd|ttd|ttd|ttd|ttd|ttddS)Nz%z%z'z5z3)rreprrFrGrrr#rrErrr test_repr3s(    zFutureTests.test_reprcCsttd}ttd}ttd}ttd}tttd}ttdd}||| |j t| || |j t||| |j t||| |j t| || |j t| || |j tdS)Nrrr\r!) rr r r r rOSErrorrrrrr)rFrf2Zf3Zf4Zf5Zf6rrr test_cancelDs$     zFutureTests.test_cancelcCsX|t|t|t|t|t|tdSr) rrFrrGrrrr#rrErrrtest_cancelled^s zFutureTests.test_cancelledcCsX|t|t|t|t|t|tdSr) rrFrrGrrrr#rrErrr test_donefs zFutureTests.test_donecCsX|t|t|t|t|t|tdSr) rrFrunningrrGrrr#rrErrr test_runningns zFutureTests.test_runningcCsz|jtjtjdd|jtjtjdd|jtjtjdd|jtjtjdd|jt t jdd| t jddddS)Nrr6r ) rr r8rFrrGCancelledErrorrrrr#rrrErrrtest_result_with_timeoutvsz$FutureTests.test_result_with_timeoutcsJfdd}ttdtj|d}||jddd|dS)NcstdddS)Nrr )r)r*rBrrrr notifications z:FutureTests.test_result_with_success..notificationrtargetr\r6r )rr rThreadstartrrrrFrr,rrrtest_result_with_successs    z$FutureTests.test_result_with_successcsLfdd}ttdtj|d}||jtjjt j d| dS)NcstddSNr)r)r*rrrrrrs z9FutureTests.test_result_with_cancel..notificationrrr6) rr rrrrr rrrr`rrrrrtest_result_with_cancels   z#FutureTests.test_result_with_cancelcCs|jtjtjdd|jtjtjdd|jtjtjdd|jtjtjdd| t t jddt | tjddddS)Nrr6)rr r8rFrrGrrrr isinstancer#rrrrErrrtest_exception_with_timeouts z'FutureTests.test_exception_with_timeoutcsPfdd}ttdtj|d}||tjtj dt | dS)NcsLtdj(t_t_jWdn1s>0YdSr)r)r* _conditionrrrr notify_allrrrrrs  z=FutureTests.test_exception_with_success..notificationrrr6) rr rrrrrrrr`rrrrrrtest_exception_with_successs    z'FutureTests.test_exception_with_successcCsnttd}|d|tjd|dWdn1sB0Y|||| ddS)Nrrz=FINISHED: r) rr rBrcr InvalidStateErrorrrrr)rFrrrrtest_multiple_set_results  (z$FutureTests.test_multiple_set_resultcCshttd}t}|||tjd|tWdn1sJ0Y|| |dS)NrzBFINISHED: ) rr r@rrcr r r+rr)rFrrrrrtest_multiple_set_exceptions  *z'FutureTests.test_multiple_set_exceptionN)rHrIrJrrrrrrrrrrrrrrrrrr r r rrrrrs(        rcCs tadSr)rrU _threads_keyrrrr setUpModulesrcCstjttjdSr)rrYr multiprocessingutil_cleanup_testsrrrrtearDownModules r__main__)N)N)_r>r import_moduleZ*skip_if_broken_multiprocessing_synchronizeZ test.supportrZtest.support.script_helperrrr:r;Zlogging.handlersrrmrr/rr)rr@rr concurrentr concurrent.futures._baser r r r rrrZconcurrent.futures.processrrrZmultiprocessing.processZmultiprocessing.utilrrFrGrrrr#rr5r%r(r-r3r6r7rCobjectrDrKrSZTestCaserTr[r{r}rrrrrrrrr r+r2rJrfrvrrrrrrrrrrrrrr rrrHmainrrrrs       $         *   ;k_HePU&p