
    daf"                        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
 d dlmZ ddlmZmZ ddlmZmZmZmZmZ  G d	 d
      Z G d de      Z e e       eeeef       d Zedk(  r ej6                          yy)    N)futures)BrokenProcessPool)support)hashlib_helper   )ExecutorTestmul)ProcessPoolForkMixinProcessPoolForkserverMixinProcessPoolSpawnMixincreate_executor_testssetup_modulec                       e Zd Zd Zd Zy)EventfulGCObjc                 .    |j                         | _        y N)Eventevent)selfmgrs     I/root/Python-3.12.4/Lib/test/test_concurrent_futures/test_process_pool.py__init__zEventfulGCObj.__init__   s    YY[
    c                 8    | j                   j                          y r   )r   setr   s    r   __del__zEventfulGCObj.__del__   s    

r   N)__name__
__module____qualname__r   r    r   r   r   r      s    !r   r   c                       e Zd Z ej                  ej                  dk(  d      d        Zd Zd Z	e
d        Zd Z ej                  d      d	        Zd
 Zd Zd Zd Zd Zd Zd Zy)ProcessPoolExecutorTestwin32zWindows-only process limitc                     | j                  t        d      5  t        j                  d       d d d        y # 1 sw Y   y xY w)Nzmax_workers must be <= 61>   )max_workers)assertRaisesRegex
ValueErrorr   ProcessPoolExecutorr   s    r   test_max_workers_too_largez2ProcessPoolExecutorTest.test_max_workers_too_large   s9    ##J$?A 	8''B7	8 	8 	8s	   7A c                    | j                   j                  t        j                  d      g}t	        t        | j                   j                  j                                     }|j                          |D ]"  }| j                  t        |j                         $ | j                  t        | j                   j                  t        dd       y )N         )executorsubmittimesleepnextiter
_processesvalues	terminateassertRaisesr   resultpow)r   r   pfuts       r   test_killed_childz)ProcessPoolExecutorTest.test_killed_child"   s     ==''

A67dmm..55789	 	=C/<	= 	+T]]-A-A31Mr   c                 h     fd}t        t        t        t        d      t        d                  } j	                  t         j
                  j                  t        t        d      t        d      d            |        j	                  t         j
                  j                  t        t        d      t        d      d            |        j	                  t         j
                  j                  t        t        d      t        d      d            |        j                  t        |       y )Nc            	          t         j                  j                  t        t	        d      t	        d      d             y )N(   	chunksize)listr0   mapr;   ranger   s   r   bad_mapz;ProcessPoolExecutorTest.test_map_chunksize.<locals>.bad_map/   s+    ""3b	59"KLr   rA      rC   2   )rE   rF   r;   rG   assertEqualr0   r9   r)   )r   rH   refs   `  r   test_map_chunksizez*ProcessPoolExecutorTest.test_map_chunksize.   s    	M 3sE"IuRy12""3b	59"JK	 	""3b	59"KL	 	""3b	59"KL	 	*g.r   c                     t        d      )N{   RuntimeError)clss    r   _test_tracebackz'ProcessPoolExecutorTest._test_traceback>   s    3r   c                    | j                   j                  | j                        }| j                  t              5 }|j                          d d d        j                  }| j                  t        |      t               | j                  |j                  d       |j                  }| j                  t        |      t        j                  j                         | j!                  d|j"                         t%        j&                         5 }	 |# 1 sw Y   xY w# t        $ r' t)        j*                  t)        j,                           Y nw xY w	 d d d        n# 1 sw Y   nxY w| j!                  dj/                                y )N)rO   z&raise RuntimeError(123) # some comment)r0   r1   rS   r9   	Exceptionr:   	exceptionassertIstyperQ   rK   args	__cause__r   process_RemoteTracebackassertIntbr   captured_stderrsys
excepthookexc_infogetvalue)r   futurecmexccausef1s         r   test_tracebackz&ProcessPoolExecutorTest.test_tracebackB   s!    %%d&:&:;y) 	RMMO	 lld3i.6*d5k7??#C#CD>I$$& 	0"0		 	   0/0/		0 	0 	0
 	>kkm	%s5   D
EDD-E
E	E

EE md5c                 x   | j                         j                         }t        |      }| j                  j	                  t
        |      }|j                          | j                  |j                  j                  d             d }t        j                          |j                          |j                          y )Nr   )timeout)get_contextManagerr   r0   r1   idr:   
assertTruer   waitr   
gc_collectshutdownjoin)r   r   objrd   s       r   test_ressources_gced_in_workersz7ProcessPoolExecutorTest.test_ressources_gced_in_workersX   s      ((*C %%b#.		q12 
r   c                 p   | j                   }| j                         }|j                  d      }d|j                  z  }t	        |      D ]  }|j                  |j                          | j                  t        |j                        |j                         t	        |      D ]  }|j                           y )Nr      )r0   rm   	Semaphore_max_workersrG   r1   acquirerK   lenr6   release)r   r0   
mp_contextsem	job_count_s         r   test_saturationz'ProcessPoolExecutorTest.test_saturationk   s    ==%%'
""1%...	y! 	)AOOCKK(	)X00183H3HIy! 	AKKM	r   c                    | j                   }|j                  dk\  sJ | j                         j                  d      dk(  rt	        j
                  d      |j                  t        dd      j                          |j                  t        dd	      j                          |j                  t        d
d      j                          | j                  t        |j                        d       y )N   F
allow_nonefork(Incompatible with the fork start method.   r.   rI      r-      r   )r0   rz   rm   get_start_methodunittestSkipTestr1   r	   r:   rK   r|   r6   r   r0   s     r   test_idle_process_reuse_onez3ProcessPoolExecutorTest.test_idle_process_reuse_onev   s    ==$$)))..%.@FJ##$NOOR#**,Q"))+Q#**,X00115r   c                    | j                   }|j                  dk  sJ | j                         j                  d      dk(  rt	        j
                  d      |j                  t        dd      j                          |j                  t        dd	       |j                  t        d	d
      j                          |j                  t        dd       |j                  t        dd      j                          |j                  t        dd       | j                  t        |j                        d       |j                          y )N   Fr   r   r      r   !               r   r.   r   	   r-   )r0   rz   rm   r   r   r   r1   r	   r:   assertLessEqualr|   r6   rs   r   s     r    test_idle_process_reuse_multiplez8ProcessPoolExecutorTest.test_idle_process_reuse_multiple   s    ==$$)))..%.@FJ##$NOOR#**,R$R$++-R$Q"))+Q"S!4!45q9r   c                    | j                         }|j                  d      dk(  r3| j                  t              5  | j	                  d|d       d d d        y | j	                  d|d      }|j                  t        j                        }|j                         }|j                  t        j                        }| j                  |j                         |       | j                  t        |j                        d       |j                  t        j                        }| j                  |j                         |       |j                  t        j                        }|j                         }| j                  ||       | j                  t        |j                        d       |j                          y # 1 sw Y   y xY w)NFr   r   r   r-   r~   max_tasks_per_child)rm   r   r9   r)   executor_typer1   osgetpidr:   rK   r|   r6   assertNotEqualrs   )	r   contextr0   rh   original_pidf2f3f4new_pids	            r   test_max_tasks_per_childz0ProcessPoolExecutorTest.test_max_tasks_per_child   s^   ""$##u#5?"":. Q""1a"PQ %%g1 & >__RYY'yy{__RYY'l3X00115__RYY'l3 __RYY'))+L'2X00115/Qs   F66F?c                 ~    | j                  dd      }| j                  |j                  j                         d       y )Nr   r-   )r   spawn)r   rK   _mp_contextr   r   s     r   2test_max_tasks_per_child_defaults_to_spawn_contextzJProcessPoolExecutorTest.test_max_tasks_per_child_defaults_to_spawn_context   s8     %%aQ%?-->>@'Jr   c                    | j                         }|j                  d      dk(  rt        j                  d      | j	                  d|d      }g }t        d      D ])  } |j                  |j                  t        ||             + |j                          t        |      D ]/  \  }}| j                  |j                         t        ||             1 y )	NFr   r   r   r-   r   r   rI   )rm   r   r   r   r   rG   appendr1   r	   rs   	enumeraterK   r:   )r   r   r0   r   ird   s         r   test_max_tasks_early_shutdownz5ProcessPoolExecutorTest.test_max_tasks_early_shutdown   s    ""$##u#5?##$NOO %%g1 & >q 	7AGNN8??3156	7"7+ 	9IAvV]]_c!Qi8	9r   c           
         | j                         }t        j                  dfd}t        j                  t        d|      5  | j                  d|      }|5  | j                  t              5  t        |j                  t        dgdz               d d d        d d d        |j                          d d d        y # 1 sw Y   *xY w# 1 sw Y   .xY w# 1 sw Y   y xY w)Nr   c                 @    dk\  rt        d      dz   | g| S )Nr   z/can't create new thread at interpreter shutdownrP   )funcrY   nthreadorig_start_new_threads     r   mock_start_new_threadzUProcessPoolExecutorTest.test_python_finalization_error.<locals>.mock_start_new_thread   s5    !|" $: ; ;qLG(555r   _start_new_threadr.   )r'   r~   )r.   r-   
   )rm   	threadingr   r   	swap_attrr   r9   r   rE   rF   r	   rs   )r   r   r   r0   r   r   s       @@r   test_python_finalization_errorz6ProcessPoolExecutorTest.test_python_finalization_error   s     ""$ !* ; ;	6 y*=46 	 ))aG)LH ;&&'89 ;cF8b=9:;; 	  	 ; ;; ;	  	 s<   CC2$B?CC?CCC	CC N)r   r   r    r   
skipUnlessr`   platformr+   r>   rM   classmethodrS   ri   r   requires_hashdigestrv   r   r   r   r   r   r   r   r!   r   r   r#   r#      s    Xw.0LM8 N8

N/     %, (^''. /$	68K9 r   r#   )executor_mixinsc                      t                y r   )r   r!   r   r   setUpModuler      s    Nr   __main__)r   r`   r   r2   r   
concurrentr   concurrent.futures.processr   testr   test.supportr   r0   r   r	   utilr
   r   r   r   r   r   r#   globalsr   r   mainr!   r   r   <module>r      s    	 
     8  ' ') )
  l  D gi!8';'A'<'>? zHMMO r   