
    daf\                         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 ddlmZmZmZ  G d deee      Zd	 Zed
k(  r ej,                          yy)    N)futures)support   )ExecutorTestmul)BaseTestCaseThreadPoolMixinsetup_modulec                       e Zd Zd Zd Zd Zd Z ej                   e	e
d      d       ej                  d      d               Zd	 Zy
)ThreadPoolExecutorTestc                     g fd}| j                   j                  |t        d             | j                   j                  d       | j	                  t        d             y)zTests verifying issue 11777.c                 (    j                  |        y N)append)nfinisheds    H/root/Python-3.12.4/Lib/test/test_concurrent_futures/test_thread_pool.pyrecord_finishedzRThreadPoolExecutorTest.test_map_submits_without_iteration.<locals>.record_finished   s    OOA    
   TwaitN)executormaprangeshutdownassertCountEqual)selfr   r   s     @r   "test_map_submits_without_iterationz9ThreadPoolExecutorTest.test_map_submits_without_iteration   sP    	 	/595D)hb	2r   c                     | j                         }t        dt        j                         xs ddz         }| j	                  |j
                  |       y )N    r      )executor_typeminos	cpu_countassertEqual_max_workers)r   r   expecteds      r   test_default_workersz+ThreadPoolExecutorTest.test_default_workers   sB    %%'rBLLN/a145..9r   c                    | j                  d      }d }t        j                  d      }t        d|j                  z        D ]  }|j                  ||        | j                  t        |j                        |j                         t        d|j                  z        D ]  }|j                           |j                  d       y )Nr"   c                 $    | j                          y r   )acquire)locks    r   acquire_lockz<ThreadPoolExecutorTest.test_saturation.<locals>.acquire_lock!   s    LLNr   r      Tr   )r#   	threading	Semaphorer   r(   submitr'   len_threadsreleaser   )r   r   r/   semis        r   test_saturationz&ThreadPoolExecutorTest.test_saturation   s    %%a(	 !!!$rH1112 	/AOOL#.	/X../1F1FGrH1112 	AKKM	t$r   c                 p   | j                         }|j                  t        dd      j                          |j                  t        dd      j                          |j                  t        dd      j                          | j	                  t        |j                        d       |j                  d	       y )
N                  r   Tr   )r#   r3   r   resultr'   r4   r5   r   )r   r   s     r   test_idle_thread_reusez-ThreadPoolExecutorTest.test_idle_thread_reuse,   s    %%'R#**,Q"))+Q#**,X../3t$r   register_at_forkzneed os.register_at_forkcpuc                 R   fdt        j                  d      5 }|j                  |       t        d      D ]J  }t        j                  dt        j                  d            5 }|j                  t               d d d        L 	 d d d        y # 1 sw Y   `xY w# 1 sw Y   y xY w)Nc                 *    | j                  |        y r   )r3   )poolr3   s    r   r3   zEThreadPoolExecutorTest.test_hang_global_shutdown_lock.<locals>.submit9   s    KK%r   r   2   fork)
mp_context)r   ThreadPoolExecutorr3   r   ProcessPoolExecutormpget_contexttuple)r   rG   _workersr3   s       @r   test_hang_global_shutdown_lockz5ThreadPoolExecutorTest.test_hang_global_shutdown_lock4   s    
	& ''* 	*dKK%2Y *00r~~f?UV *ZaNN5)* **	* 	** *		* 	*s$   AB'B=
BBBB&c                 .   t        j                         g fd}| j                  d      5 }|j                  |d      }	 t	        j
                  |j                  |ddgd	            5 }| j                  t              5  t        |       d d d        d d d        j                          |j                          d d d        | j                  d
dg       y # 1 sw Y   NxY w# 1 sw Y   RxY w# j                          w xY w# 1 sw Y   KxY w)Nc                     j                  d| d       	 j                          j                  d| d       y # j                  d| d       w xY w)Nzident=z startedz stopped)r   r   )identlog
stop_events    r   
log_n_waitzRThreadPoolExecutorTest.test_executor_map_current_future_cancel.<locals>.log_n_waitG   sR    JJ&%*+0!

feXX./

feXX./s	   > Ar   )max_workersfirst)rU   secondthirdr   )timeoutzident='first' startedzident='first' stopped)r1   Eventr#   r3   
contextlibclosingr   assertRaisesTimeoutErrornextsetrA   assertListEqual)r   rX   rG   futgenrV   rW   s        @@r   'test_executor_map_current_future_cancelz>ThreadPoolExecutorTest.test_executor_map_current_future_cancelC   s    __&
	0 A. 	$++j+8C!''HHZ(G)<aHH "**<8 "S	""  JJL	 	S#:<S"TU" "" "  	 	sS   D)C6/C*CC*C6! DC'#C**C3	/C66DDDN)__name__
__module____qualname__r   r*   r9   rB   unittest
skipUnlesshasattrr%   r   requires_resourcerR   rh    r   r   r   r      s^    3:
%% X%78:TUWu%* & V*Vr   r   c                      t                y r   )r
   rp   r   r   setUpModulerr   _   s    Nr   __main__)r_   multiprocessingrM   multiprocessing.processmultiprocessing.utilr%   r1   rl   
concurrentr   testr   r   r   r   utilr   r	   r
   r   rr   ri   mainrp   r   r   <module>r{      s]        	     ' = =MV_lL MV` zHMMO r   