a ze@sddlmZededdlmZddlmZddlZddl 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/ddZ0ddZ1ddZ2ddZ3ddZ4didd 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?djdLdMZMdNdOZNdPdQZOdRdSZPdTdUZQGdVdWdWe6ZRGdXdYdYe6ZSGdZd[d[e6ZTGd\d]d]e6ZUGd^d_d_e6ZVGd`dadae6ZWGdbdcdcZXeAeXe>e@e?fd?Gdddedee;ZYdfdgZZe[dhkre\dS)k)support_multiprocessing)hashlib_helper)assert_python_okN) QueueHandler PicklingError)futures)PENDINGRUNNING CANCELLEDCANCELLED_AND_NOTIFIEDFINISHEDFutureBrokenExecutor)BrokenProcessPool) get_contextcCst}||_||_||_|SN)r_state _exception_result)state exceptionresultfrP/opt/bitninja-python-dojo/embedded/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)Nz/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) rer) 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*dSNr\rr)r r|rrrxrrrFrhresthreadsr,rrrtest_del_shutdowns  z(ThreadPoolShutdownTest.test_del_shutdowncCsFtjdd}|ttdd}|j}|jdd|D] }|q4dSNr\rrFrl)r r|rrrxrrprrrrrtest_shutdown_no_waits   z,ThreadPoolShutdownTest.test_shutdown_no_waitcCsTtjddd}|ttdd|j}~t|D]}||j d| q4dS)Nr\Z SpecialPool)r_Zthread_name_prefixrz^SpecialPool_[0-4]$ r r|rrrxrr gc_collect assertRegexrrrFrhrr,rrrtest_thread_names_assignedsz1ThreadPoolShutdownTest.test_thread_names_assignedcCsRtjdd}|ttdd|j}~t|D]}||j d| q2dS)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_shutdowncCsjtjdd}|ttdd}|j}|j}|j}|j}~t | | D] }| qP| dSr) r rrrrx_executor_manager_threadr _call_queuerrrr join_thread)rFrhrexecutor_manager_threadr call_queuerrrrrs   z)ProcessPoolShutdownTest.test_del_shutdowncCsftjdd}|ttdd}|j}|j}|j}|jdd| | D] }| qL| dSr) r rrrrxrrrrprrr)rFrhrrr rrrrrrs    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_completed8s zWaitTests.test_first_completedcCsT|jtjd}tjtt|gtjd\}}| t ttg|| t |g|dS)Nr r ) rhrtr)r*r rmCANCELLED_AND_NOTIFIED_FUTURESUCCESSFUL_FUTURErrrPrFrfinishedpendingrrr+test_first_completed_some_already_completedCs  z5WaitTests.test_first_completed_some_already_completedcCsr|jtdd}|jtd}|jtjd}tj|||gtjd\}}| t ||g|| t |g|dS)Nrr r rr ) rhrtr%r-r)r*r rmFIRST_EXCEPTIONrrP)rFrrZfuture3rrrrrtest_first_exceptionOs zWaitTests.test_first_exceptioncCsl|jtdd}|jtjd}tjttt ||gtj d\}}| t tt |g|| t t|g|dS)Nr rr r ) rhrtdivmodr)r*r rmrrrrrrPrFrrrrrrr*test_first_exception_some_already_complete[s" 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_failedks z1WaitTests.test_first_exception_one_already_failedcCsj|jtdd}|jtdd}tjttt||gtj d\}}| t ttt||g|| t |dS)Nrrr r ) rhrtrr%r rmrrr  ALL_COMPLETEDrrPrrrrtest_all_completedus( zWaitTests.test_all_completedcCsn|jtdd}|jtjd}tjttt ||gdtj d\}}| t ttt |g|| t |g|dS)Nr\)timeoutr) rhrtr%r)r*r rmrr rr"rrPrrrr test_timeouts& zWaitTests.test_timeoutN) rHrIrJrrrrr!r#r'rrrrr 6s    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)rHrIrJr.rrrrr(sr(c@s4eZdZddZddZddZddZd d Zd S) AsCompletedTestscCsV|jtdd}|jtdd}ttttt||g}| tttt||g|dS)Nrr r%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 r0rr 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 r0 itertoolsrepeatrr)rFrr1rrrtest_duplicate_futuress z'AsCompletedTests.test_duplicate_futurescCsddtdD}|ttd|ttdd|tjNtj|ddD].}| |t |}~t ||qPWdn1s0Y|dd t|D]@}| |t |}~t |||r|dd qdS) NcSsg|] }tqSr)rrurrrrwrzGAsCompletedTests.test_free_reference_yielded_future..rr r!rr3test)rxrrr rrr r5r0removeweakrefrefrrr set_result)rF futures_listrwrrrr"test_free_reference_yielded_futures&  ,   z3AsCompletedTests.test_free_reference_yielded_futurecCs`ttttg}|tj"}ttj|ddWdn1s@0Y| t |j ddS)Nrr3z2 (of 4) futures unfinished) rPENDING_FUTURERUNNING_FUTURErrr r5rr0rstrr)rFr@rrrr"test_correct_timeout_exception_msgs 0z3AsCompletedTests.test_correct_timeout_exception_msgN)rHrIrJr2r6r9rBrFrrrrr/s  r/c@sZeZdZddZddZddZddZd d Zd d Ze j d dZ ddZ ddZ dS) ExecutorTestcCs$|jtdd}|d|dS)Nrr:)rhrtrrrrFrrrr test_submit szExecutorTest.test_submitcCs|jjtddd}|d||jjtdddd}||ddddf|t |jjtdd Wdn1s0Y|t|jjdd Wdn1s0YdS) Nrr:)r$rr)rFfn)r)rLarg)rM)rhrtr%rrr(r TypeErrorrIrrrtest_submit_keywords . 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)rhrrr__next__rZeroDivisionError)rFrrrrtest_map_exception"szExecutorTest.test_map_exceptioncCsdg}z,|jjtjgdddD]}||qWntjyDYn 0|d|ddg|dS)N)rrr$r\r3zexpected TimeoutError) rhrr)r*rr r5rr)rFresultsrrrrtest_map_timeout(s   zExecutorTest.test_map_timeoutcCs(|jtdg|jd|jdS)Nrr)rhrrErfrprErrrtest_shutdown_race_issue124566sz*ExecutorTest.test_shutdown_race_issue12456csPt}tt|fdd}|j|j~jt j d}| |ddS)NcsSr)rP)objZmy_object_collectedrrDrz7ExecutorTest.test_no_stale_references..r3z-Stale reference not collected within timeout.) rDrrLr=r>rhrtrGrmr SHORT_TIMEOUTr)rFZ my_objectZmy_object_callbackZ collectedrr[rtest_no_stale_references=s z%ExecutorTest.test_no_stale_referencesc CsFdD]<}|td|j|dWdq1s60YqdS)N)rz"max_workers must be greater than 0r)assertRaisesRegexr@re)rFZnumberrrrtest_max_workers_negativeMs z&ExecutorTest.test_max_workers_negativecCs<|jttdD]$}t|}~t||qdS)NrP) rhrrSrxr=r>rrr)rFrZrArrrtest_free_referenceTs  z ExecutorTest.test_free_referenceN)rHrIrJrJrOrSrVrXrYrZ cpython_onlyr^rarbrrrrrGs   rGc@sFeZdZddZddZddZddZee e d d d d Z d S)ThreadPoolExecutorTestcsDgfdd}|j|td|jjdd|tddS)Ncs|dSr)r)nrrrrecord_finishedbszRThreadPoolExecutorTest.test_map_submits_without_iteration..record_finishedrPTrl)rhrrxrpZassertCountEqual)rFrfrrer"test_map_submits_without_iteration_s  z9ThreadPoolExecutorTest.test_map_submits_without_iterationcCs0|}tdtpdd}||j|dS)N rr)reminos cpu_countr _max_workers)rFrhZexpectedrrrtest_default_workersisz+ThreadPoolExecutorTest.test_default_workerscCs||d}dd}td}td|jD]}|||q*|t|j|jtd|jD] }| q^|j dddS)NrcSs |dSrrrrrrrpsz.acquire_lockrTrl) rerrrxrlrtrrrrrp)rFrhrrrrrrtest_saturationns   z&ThreadPoolExecutorTest.test_saturationcCs`|}|tdd|tdd|tdd|t|jd|jdd dS) Nr rr$r%rrTrl)rertr%rrrrrprFrhrrrtest_idle_thread_reuse{s z-ThreadPoolExecutorTest.test_idle_thread_reuseregister_at_forkzneed os.register_at_forkc sfddtdf}||tdD]@}tjdtdd}|tWdq,1sb0Yq,Wdn1s0YdS)Ncs||dSrrt)poolrtrrrtszEThreadPoolExecutorTest.test_hang_global_shutdown_lock..submitrrr~)r`)r r|rtrxrrtuple)rFrurRworkersrrtrtest_hang_global_shutdown_locks     z5ThreadPoolExecutorTest.test_hang_global_shutdown_lockN) rHrIrJrgrmrorrr skipUnlessrdrjrxrrrrrc^s   rcc@steZdZeejdkdddZddZddZ e d d Z d d Z e d ddZddZddZddZdS)ProcessPoolExecutorTestrzWindows-only process limitcCs<|tdtjddWdn1s.0YdS)Nzmax_workers must be <= 61>r)r`r@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(r_rQ)rrhrrrxrrErrbad_mapsz;ProcessPoolExecutorTest.test_map_chunksize..bad_maprr$rQr)rrrrxrrhrr@)rFrr>rrErtest_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)Nrr3)rr]ManagerrKrhrtidrrrMrmrrrpr)rFrNrZrrrrtest_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)Nrrrn) rerrrlrxrtrrrrrrp)rFrhr`rZ job_countrRrrrros      z'ProcessPoolExecutorTest.test_saturationcCs^|d}|tdd|tdd|tdd|t|jd|dS) Nrr rr$r%rrpr)rertr%rrrrrprqrrrtest_idle_process_reuse_ones  z3ProcessPoolExecutorTest.test_idle_process_reuse_onecCsh|d}|tdd|tdd|tdd|tdd|t|jd |dS) Nr r%!r)rertr%rZassertLessEqualrrrprqrrr test_idle_process_reuse_multiples z8ProcessPoolExecutorTest.test_idle_process_reuse_multipleN)rHrIrJrryr/rr|rr classmethodrrrZrequires_hashdigestrrorrrrrrrzs    rzcCs*|rt|ddl}||dSNr)r)r* faulthandlerdisableZ_sigsegv)delayrrrr_crashs  rcCstddSNr)r/exitrrrr_exitsrcCs |dSrr)Errrrr _raise_errorsrcCsddl}|t_|dSr)ioStringIOr/stderr)rrrrr_raise_error_ignore_stderrs rcCs|Srrrrrr_return_instance!src@seZdZddZdS) CrashAtPicklecCs tdSrrrErrr __reduce__(szCrashAtPickle.__reduce__NrHrIrJrrrrrr&src@seZdZddZdS)CrashAtUnpicklecCstdfSNrrrErrrr.szCrashAtUnpickle.__reduce__Nrrrrrr,src@seZdZddZdS) ExitAtPicklecCs tdSrrrErrrr4szExitAtPickle.__reduce__Nrrrrrr2src@seZdZddZdS)ExitAtUnpicklecCstdfSrrrErrrr:szExitAtUnpickle.__reduce__Nrrrrrr8src@seZdZddZdS) ErrorAtPicklecCsddlm}|ddS)NrrzError in pickle)pickler)rFrrrrr@s zErrorAtPickle.__reduce__Nrrrrrr>src@seZdZddZdS)ErrorAtUnpicklecCsddlm}t|ffS)Nr)UnpicklingError)rrr)rFrrrrrGs zErrorAtUnpickle.__reduce__NrrrrrrEsrc@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_tracebackseekreadrrrrpr.r/ __stderr__r)rFrhrrrrrrrr_fail_on_deadlockOs    &  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^r3)rhrprerr]rtrrr nullcontextrrTIMEOUTr r5r)rFerrorfuncrr&rhrrrrr _check_crashbs   Nz!ExecutorDeadlockTest._check_crashcCs|tttdSr)rrrrrErrrtest_error_at_task_pickleysz.ExecutorDeadlockTest.test_error_at_task_picklecCs|tttdSr)rrrrrErrrtest_exit_at_task_unpickle~sz/ExecutorDeadlockTest.test_exit_at_task_unpicklecCs|tttdSr)rrrrrErrrtest_error_at_task_unpicklesz0ExecutorDeadlockTest.test_error_at_task_unpicklecCs|tttdSr)rrrrrErrrtest_crash_at_task_unpicklesz0ExecutorDeadlockTest.test_crash_at_task_unpicklecCs|ttdSr)rrrrErrr%test_crash_during_func_exec_on_workersz:ExecutorDeadlockTest.test_crash_during_func_exec_on_workercCs|ttdSr)r SystemExitrrErrr$test_exit_during_func_exec_on_workersz9ExecutorDeadlockTest.test_exit_during_func_exec_on_workercCs|tttdSr)rrrrErrr%test_error_during_func_exec_on_workersz: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]rrrrrrrrrrrrrrrrrrrrrrLs" 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_resultrrrLsz6FutureTests.test_done_callback_with_result..fnr\)radd_done_callbackr?rrFrLrrrrtest_done_callback_with_results    z*FutureTests.test_done_callback_with_resultcs@dfdd}t}|||td|djdS)Ncs |dSrrrZcallback_exceptionrrrLsz9FutureTests.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_cancelledrrrLsz6FutureTests.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_calledrrrL sz1FutureTests.test_done_callback_raises..fnr\zException: doh!)rrrrr?rrr)rFrrrLrr)rrrtest_done_callback_raisess        z%FutureTests.test_done_callback_raisescs:dfdd}t}|d|||ddS)Ncs |dSrrrrrrrLsz=FutureTests.test_done_callback_already_successful..fnr\)rr?rrrrrr%test_done_callback_already_successfuls    z1FutureTests.test_done_callback_already_successfulcs@dfdd}t}|td|||djdS)Ncs |dSrrrrrrrL#sz9FutureTests.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 |dSrrrrrrrL.sz.fn)rrrrrrrr$test_done_callback_already_cancelled,s   z0FutureTests.test_done_callback_already_cancelledcCsntR}dd}t}|d|||d||d|Wdn1s`0YdS)NcSs tddS)Nrrrrrrr9szKFutureTests.test_done_callback_raises_already_succeeded..raising_fnr\zexception calling callback forr)rrrr?rrr)rFrrrrrr+test_done_callback_raises_already_succeeded7s   z7FutureTests.test_done_callback_raises_already_succeededcCsd|ttd|ttd|ttd|ttd|ttd|ttddS)Nz%z%z'z5z3)rreprrCrDrrr rrErrr test_reprGs(    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_cancelXs$     zFutureTests.test_cancelcCsX|t|t|t|t|t|tdSr) rrCrrDrrrr rrErrrtest_cancelledrs zFutureTests.test_cancelledcCsX|t|t|t|t|t|tdSr) rrCrrDrrrr rrErrr test_donezs zFutureTests.test_donecCsX|t|t|t|t|t|tdSr) rrCrunningrrDrrr rrErrr test_runnings zFutureTests.test_runningcCsz|jtjtjdd|jtjtjdd|jtjtjdd|jtjtjdd|jt t jdd| t jddddS)Nrr3r ) rr r5rCrrDCancelledErrorrrrr rrrErrrtest_result_with_timeoutsz$FutureTests.test_result_with_timeoutcsJfdd}ttdtj|d}||jddd|dS)NcstdddS)Nrr )r)r*r?rrrr notifications z:FutureTests.test_result_with_success..notificationrtargetr\r3r )rr rThreadstartrrrrFrr,rrrtest_result_with_successs    z$FutureTests.test_result_with_successcsLfdd}ttdtj|d}||jtjjt j d| dS)NcstddSr)r)r*rrrrrrs z9FutureTests.test_result_with_cancel..notificationrrr3) rr rrrrr rrrr]rrrrrtest_result_with_cancels   z#FutureTests.test_result_with_cancelcCs|jtjtjdd|jtjtjdd|jtjtjdd|jtjtjdd| t t jddt | tjddddS)Nrr3)rr r5rCrrDrrrr 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..notificationrrr3) rr rrrrrrrr]rrrrrrtest_exception_with_successs    z'FutureTests.test_exception_with_successcCsnttd}|d|tjd|dWdn1sB0Y|||| ddS)Nrrz=FINISHED: r) rr r?r`r InvalidStateErrorrrrr)rFrrrrtest_multiple_set_results  (z$FutureTests.test_multiple_set_resultcCshttd}t}|||tjd|tWdn1sJ0Y|| |dS)NrzBFINISHED: ) rr r@rr`r r r+rr)rFrrrrrtest_multiple_set_exceptions  *z'FutureTests.test_multiple_set_exceptionN)rHrIrJrrrrrrrrrrrrrrrrr r rrrrrrrs(        rcCs.ttjjt}tjtjg|RdSr)rZaddModuleCleanupmultiprocessingutil_cleanup_testsrrUrY) thread_inforrr setUpModulesr__main__)N)N)]r;r import_moduleZ*skip_if_broken_multiprocessing_synchronizeZ test.supportrZtest.support.script_helperrrr7r;Zlogging.handlersrrjrr/rr)rr=rr concurrentr concurrent.futures._baser r r r rrrZconcurrent.futures.processrrrZmultiprocessing.processZmultiprocessing.utilrrCrDrrrr rr5r%r(r-r3r6r7rCobjectrDrKrSZTestCaserTr[r{r}rrrrrrrrr r(r/rGrcrzrrrrrrrrrrrrrrrHmainrrrrs       $         *   ;kaIeRV4p