+
    BiS<                         ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RI	H
t
 ^RIHtHtHtHtHtHtHt R t ! R R4      t ! R	 R
]]]4      t ! R R]4      t]! ]! 4       ]]]]3R7       R t]R8X  d   ]P4                  ! 4        R# R# )    N)futures)support)assert_python_ok)BaseTestCaseThreadPoolMixinProcessPoolForkMixinProcessPoolForkserverMixinProcessPoolSpawnMixincreate_executor_testssetup_modulec                     \         P                  ! V 4       \        V4       \        P                  P                  4        R # N)timesleepprintsysstdoutflush)tmsgs   &&A/usr/lib/python3.14/test/test_concurrent_futures/test_shutdown.pysleep_and_printr      s$    JJqM	#JJJ    c                   J   a  ] tR t^t o R tR tR tR tR tR t	R t
RtV tR	# )
ExecutorShutdownTestc                    V P                   P                  4        V P                  \        V P                   P                  \
        ^^4       R#    N)executorshutdownassertRaisesRuntimeErrorsubmitpow)selfs   &r   test_run_after_shutdown,ExecutorShutdownTest.test_run_after_shutdown   s6     ,--..q!	%r   c                    \        R RP                  V P                  P                  \	        V RR4      R7      4      w  rpV P                  V4       V P                  VP                  4       R4       R# )-caY  if 1:
            from concurrent.futures import {executor_type}
            from time import sleep
            from test.test_concurrent_futures.test_shutdown 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")
            ctx executor_typecontext   appleN)r   formatr-   __name__getattrassertFalseassertEqualstripr%   rcouterrs   &   r   test_interpreter_shutdown.ExecutorShutdownTest.test_interpreter_shutdown   sh    ' / T%7%7%@%@&tUB7  9:" 	h/r   c                   \        R RP                  V P                  P                  \	        V RR4      R7      4      w  rpV P                  RVP                  4       4       V P                  VP                  4       R4       R# )r)   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-errorN)	r   r0   r-   r1   r2   assertIndecoder4   r5   r6   s   &   r   &test_submit_after_interpreter_shutdown;ExecutorShutdownTest.test_submit_after_interpreter_shutdown4   sp    ' /& T%7%7%@%@&tUB7  9':. 	A3::<P&67r   c                    \        ^24       Uu. uF,  qP                  P                  \        P                  R4      NK.  	  ppV P                  P                  4        V F  pVP                  4        K  	  R# u upi )2   皙?N)ranger   r#   r   r   r    result)r%   _fsfs   &   r   test_hang_issue12364)ExecutorShutdownTest.test_hang_issue12364P   sV    =B2YGYmm""4::s3YG AHHJ  Hs   2A7c                   V P                   ^8:  g   Q R4       h\        ^24       Uu. uF,  qP                  P                  \        P
                  R4      NK.  	  ppV P                  P                  RR7       V Uu. uF  q3P                  4       '       g   K  VNK  	  ppV P                  \        V4      ^4       V Uu. uF  q3P                  4       '       d   K  VNK  	  ppV FQ  pV P                  VP                  4       RVP                  : 2R7       V P                  VP                  4       4       KS  	  V P                  \        V4      ^ 4       R# u upi u upi u upi )   ztest needs few workersrC   T)cancel_futureszfut._state=)r   N)worker_countrD   r   r#   r   r   r    	cancelledassertGreaterlen
assertTruedone_stateassertIsNone	exception)r%   rF   rG   futrO   otherss   &     r   test_cancel_futures(ExecutorShutdownTest.test_cancel_futuresV   s     A%?'??%<A"IFIqmm""4::r2IFd3 %':BS--/SSB	:3y>2.
 "$;#==?##;COOCHHJ{szzm,<O=cmmo.  	3v;*' G
 ; <s   2E:EE=EEc                P   V P                   \        P                  8X  d   \        P                  ! R4      h\        RRP                  V P                   P                  \        V RR4      R7      4      w  rpV P                  V4       V P                  VP                  4       R4       R# )zushutdown(wait=False) doesn't hang at exit with running futures.

See https://github.com/python/cpython/issues/83386.
z9Hangs, see https://github.com/python/cpython/issues/83386r)   a  if True:
            from concurrent.futures import {executor_type}
            from test.test_concurrent_futures.test_shutdown import sleep_and_print
            if __name__ == "__main__":
                if {context!r}: multiprocessing.set_start_method({context!r})
                t = {executor_type}(max_workers=3)
                t.submit(sleep_and_print, 1.0, "apple")
                t.shutdown(wait=False)
            r*   Nr,   r/   )r-   r   ProcessPoolExecutorunittestSkipTestr   r0   r1   r2   r3   r4   r5   r6   s   &   r   test_hang_gh83386&ExecutorShutdownTest.test_hang_gh83386m   s    
 !<!<<##KM M ( / T%7%7%@%@&tUD9  ;	< 	h/r   c                   \        \        R4      '       g   \        P                  ! R4      hR p/ p\	        V RR4      '       d   V P                  4       VR&   V P                  ! R
R^/VB pVP                  \        4      P                  4        \        P                  ! \        P                  V4      p \        P                  ! ^4       VP                  \        4      P                  4        VP                  RR	7       \        P                  ! ^ 4       \        P                  ! \        P                  V4       R#   \        P                  ! ^ 4       \        P                  ! \        P                  T4       i ; i)zshutdown(wait=True) doesn't hang when a future was submitted and
quickly canceled right before shutdown.

See https://github.com/python/cpython/issues/94440.
alarmz1Tested platform does not support the alarm signalc                     \        R 4      h)ztimed out waiting for shutdown)r"   )_signum_frames   &&r   timeout7ExecutorShutdownTest.test_hang_gh94440.<locals>.timeout   s    ?@@r   r*   N
mp_contextmax_workersTwait )hasattrsignalr]   r^   r2   get_contextr-   r#   intrE   SIGALRMrb   cancelr    )r%   rf   kwargsr   old_handlers   &    r   test_hang_gh94440&ExecutorShutdownTest.test_hang_gh94440   s    vw''##CE E	A 4%%#'#3#3#5F< %%>!>v>##%mmFNNG<	7LLOOOC '')4(LLOMM&..+6 LLOMM&..+6s   5AD= ==E:rl   N)r1   
__module____qualname____firstlineno__r&   r:   r?   rI   rY   r_   ru   __static_attributes____classdictcell____classdict__s   @r   r   r      s-     %0,88+.0,7 7r   r   c                   J   a  ] tR t^t o R tR tR tR tR tR t	R t
RtV tR	# )
ThreadPoolShutdownTestc                   R  p\         P                  ! ^ 4      p\        ^4       F  pV P                  P	                  W4       K   	  V P                  \        V P                  P                  4      ^4       \        ^4       F  pVP                  4        K  	  V P                  P                  4        V P                  P                   F  pVP                  4        K  	  R# )c                 &    V P                  4        R # r   acquirelocks   &r   acquire_lockCThreadPoolShutdownTest.test_threads_terminate.<locals>.acquire_lock       LLNr   N)	threading	SemaphorerD   r   r#   r4   rQ   _threadsreleaser    join)r%   r   semir   s   &    r   test_threads_terminate-ThreadPoolShutdownTest.test_threads_terminate   s    	 !!!$qAMM  3 T]]334a8qAKKM  ''AFFH (r   c                <   \         P                  ! ^R7      ;_uu_ 4       pTpV P                  \        VP	                  \
        \        R^4      4      4      . RO4       RRR4       XP                   F  pVP                  4        K  	  R#   + '       g   i     L5; i)rL   ri   N
rL         r      r   r   r   r   r   )	r   ThreadPoolExecutorr4   listmapabsrD   r   r   )r%   er   r   s   &   r   test_context_manager_shutdown4ThreadPoolShutdownTest.test_context_manager_shutdown   sl    ''A66!HT!%%U2q\":;;= 7
 ""AFFH # 76s   >BB	c           
     Z   \         P                  ! ^R7      pVP                  \        \	        R^4      4      pVP
                  p?V F  pVP                  4        K  	  \        \        V\	        R^4      4       UUu. uF  w  rVV\        V4      8H  NK  	  upp4      '       g   Q hR# u uppi )rL   r   Nr   )	r   r   r   r   rD   r   r   allzipr%   r   resthreadsr   rvs   &      r   test_del_shutdown(ThreadPoolShutdownTest.test_del_shutdown   s    --!<ll3b!-##AFFH 
 CU2q\,BC,BDAAQK,BCDDDDCs   <B'
c           
     |   \         P                  ! ^R7      pVP                  \        \	        R^4      4      pVP
                  pVP                  RR7       V F  pVP                  4        K  	  \        \        V\	        R^4      4       UUu. uF  w  rVV\        V4      8H  NK  	  upp4      '       g   Q hR# u uppi )rL   r   Frj   Nr   )
r   r   r   r   rD   r   r    r   r   r   r   s   &      r   test_shutdown_no_wait,ThreadPoolShutdownTest.test_shutdown_no_wait   s     --!<ll3b!-##u%AFFH 
 CU2q\,BC,BDAAQK,BCDDDDCs   B8
c                $   \         P                  ! ^RR7      pVP                  \        \	        R^4      4       VP
                  p?\        P                  ! 4        V F/  pV P                  VP                  R4       VP                  4        K1  	  R# )rL   SpecialPool)ri   thread_name_prefixz^SpecialPool_[0-4]$Nr   r   r   r   r   rD   r   r   
gc_collectassertRegexnamer   r%   r   r   r   s   &   r   test_thread_names_assigned1ThreadPoolShutdownTest.test_thread_names_assigned   sm    --m=S%A,'##AQVV%;<FFH r   c                "   \         P                  ! ^R7      pVP                  \        \	        R^4      4       VP
                  p?\        P                  ! 4        V F/  pV P                  VP                  R4       VP                  4        K1  	  R# )rL   r   zThreadPoolExecutor-\d+_[0-4]$Nr   r   r   s   &   r   test_thread_names_default0ThreadPoolShutdownTest.test_thread_names_default   sj    --!<S%A,'##A QVV%EFFFH	 r   c                    \        R R4      w  rpV P                  V4       V P                  VP                  4       RR.4       R# )r)   ai  if True:
            from concurrent.futures import ThreadPoolExecutor
            from test.test_concurrent_futures.test_shutdown 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   N)r   r3   r=   r5   r6   s   &   r   test_cancel_futures_wait_false5ThreadPoolShutdownTest.test_cancel_futures_wait_false   sC     ( /  	 	ciikHc?3r   rl   N)r1   rw   rx   ry   r   r   r   r   r   r   r   rz   r{   r|   s   @r   r   r      s/     EE
4 4r   r   c                   j   a  ] tR t^t o R tR tR tR t]R 4       t	]R 4       t
R tR tR	 tR
tV tR# )ProcessPoolShutdownTestc                D   R  pV P                  4       pVP                  RR7      R8X  d   V P                  pM^pVP                  ^ 4      p\	        ^4       F  pV P
                  P                  W4       K   	  V P                  \        V P
                  P                  4      V4       \	        ^4       F  pVP                  4        K  	  V P
                  P                  pV P
                  P                  4        VP                  4        F  pVP                  4        K  	  R# )c                 &    V P                  4        R # r   r   r   s   &r   r   FProcessPoolShutdownTest.test_processes_terminate.<locals>.acquire_lock  r   r   F)
allow_noneforkN)ro   get_start_methodrN   r   rD   r   r#   r4   rQ   
_processesr   r    valuesr   )r%   r   rh   expected_num_processesr   rF   	processesps   &       r   test_processes_terminate0ProcessPoolShutdownTest.test_processes_terminate   s    	 %%'
&&%&8FB%)%6%6"%&"""1%qAMM  3 T]]5568NOqAKKM MM,,	 !!#AFFH $r   c                v   \         P                  ! ^V P                  4       R7      ;_uu_ 4       pVP                  pV P	                  \        VP                  \        \        R^4      4      4      . RO4       RRR4       XP                  4        F  pVP                  4        K  	  R#   + '       g   i     L9; i)rL   ri   rh   Nr   r   )r   r\   ro   r   r4   r   r   r   rD   r   r   )r%   r   r   r   s   &   r   r   5ProcessPoolShutdownTest.test_context_manager_shutdown  s    (($*:*:*<> >ABIT!%%U2q\":;;=> !!#AFFH $> >s   AB((B8	c           
     F   \         P                  ! ^V P                  4       R7      pVP                  \        \        R^4      4      pVP                  pVP                  pVP                  pVP                  p?\        P                  ! 4        VP                  4        VP                  4        F  pVP                  4        K  	  VP                  4        \        \        V\        R^4      4       UUu. uF  w  rxV\	        V4      8H  NK  	  upp4      '       g   Q hR# u uppi )rL   r   Nr   )r   r\   ro   r   r   rD   _executor_manager_threadr   _call_queuer   r   r   r   join_threadr   r   )	r%   r   r   executor_manager_threadr   
call_queuer   r   r   s	   &        r   r   )ProcessPoolShutdownTest.test_del_shutdown!  s    ..$*:*:*<>ll3b!-"*"C"C''	))
"*"C"C 	 $$&!!#AFFH $  CU2q\,BC,BDAAQK,BCDDDDCs   2D
c           
     &   \         P                  ! ^V P                  4       R7      pVP                  \        \        R^4      4      pVP                  pVP                  pVP                  pVP                  RR7       VP                  4        VP                  4        F  pVP                  4        K  	  VP                  4        \        \        V\        R^4      4       UUu. uF  w  rxV\	        V4      8H  NK  	  upp4      '       g   Q hR# u uppi )rL   r   Frj   Nr   )r   r\   ro   r   r   rD   r   r   r   r    r   r   r   r   r   )	r%   r   r   r   r   r   r   r   r   s	   &        r   r   -ProcessPoolShutdownTest.test_shutdown_no_wait7  s     ..$*:*:*<>ll3b!-''	))
"*"C"Cu% 	 $$&!!#AFFH $  CU2q\,BC,BDAAQK,BCDDDDCs   "D
c                    \        R 4      h)zfailing task)
ValueErrorclsns   &&r   _failing_task_gh_132969/ProcessPoolShutdownTest._failing_task_gh_132969M  s    ((r   c                @    \         P                  ! R V,          4       V# )rC   )r   r   r   s   &&r   _good_task_gh_132969,ProcessPoolShutdownTest._good_task_gh_132969Q  s    

37r   c                   V P                  4       P                  4       pVR 8X  g-   VR8X  d;   \        P                  P	                  R4      '       d   V P                  RV: 24       \        P                  ! V^V P                  4       R7      pVP                  \        P                  ^4      pVP                  \        P                  ^4      pVP                  \        P                  ^4      p^ p WtP                  4       ,          pWuP                  4       ,          pWvP                  4       ,          pVP                  pVP                  RR7       \         P"                  ! R4       VP%                  4        V#   \         d     LSi ; i)r   
forkserverwinz!Skipping test for start_method = )ri   max_tasks_per_childrh   Frj   g?)ro   r   r   platform
startswithskipTestr   r\   r#   r   r   r   rE   r   r   r    r   r   r   )	r%   ri   start_methodr   f1f2f3rE   r   s	   &&       r   _run_test_issue_gh_1329691ProcessPoolShutdownTest._run_test_issue_gh_132969V  s@    '')::<F"L(S\\-D-DU-K-K B<2CDE..'$%++-/ __4II1M__4LLaP__4II1M	iik!Fiik!Fiik!F #+"C"Cu%

3$$&  		s   1AE9 9FFc                L    V P                  ^4      pV P                  V^4       R# r   r   r4   r%   rE   s   & r   test_shutdown_gh_132969_case_16ProcessPoolShutdownTest.test_shutdown_gh_132969_case_1z  s$     //2#r   c                L    V P                  ^4      pV P                  V^4       R# )r   Nr   r   s   & r   test_shutdown_gh_132969_case_26ProcessPoolShutdownTest.test_shutdown_gh_132969_case_2  s$     //2#r   rl   N)r1   rw   rx   ry   r   r   r   r   classmethodr   r   r   r   r   rz   r{   r|   s   @r   r   r      sX     .E,E, ) )  "H$$ $r   r   )executor_mixinsc                      \        4        R # r   )r   rl   r   r   setUpModuler     s    Nr   __main__)rn   r   r   r   r]   
concurrentr   testr   test.support.script_helperr   utilr   r   r   r	   r
   r   r   r   r   r   r   globalsr   r1   mainrl   r   r   <module>r     s     
      7) ) )E7 E7P]4_.BL ]4@F$2 F$R gi!8';'A'<'>? zMMO r   