
    daf8                         d 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Zddl	m
Z
 ddlmZ ej                  s ej                  d       G d de
      Zd Zed	k(  r ej$                          yy)
z.This test checks for correct fork() behavior.
    N)ForkWait)supportz$test module requires working os.forkc                       e Zd Zd Zd Zy)ForkTestc                   	 t        j                         dd	d	fd}t        j                  |      }|j                          j	                          d}t        j                         }	 |sZt              }|k(  rt        j                  |       nWt        j                  dkD  rt        d       t        j                  d       n#|j                          | j                  ||	       	 t        j                  |t        j                          y
# t"        $ r Y y
w xY w# 	 t        j                  |t        j                          w # t"        $ r Y w w xY wxY w)zFCheck fork() in main thread works while a subthread is doing an importzfake test modulepartialcompletec                      t        j                          t        j                  <   j	                          t        j                  d        t        j                  <   t        j                          y )Ng{Gz?)impacquire_locksysmodulessettimesleeprelease_lock)complete_modulefake_module_nameimport_startedpartial_modules   */root/Python-3.12.4/Lib/test/test_fork1.pyimporterz9ForkTest.test_threaded_import_lock_fork.<locals>.importer   sQ    ,:CKK() JJt,;CKK()    )target*      z Child encountered partial moduleexitcodeN)	threadingEventThreadstartwaitosfork
__import___exitr   verboseprintjoin	wait_implkillsignalSIGKILLOSError)
selfr   tr   pidmr   r   r   r   s
         @@@@r   test_threaded_import_lock_forkz'ForkTest.test_threaded_import_lock_fork   s   "*-"$	 H-		ggi	 /0'HHX&*@AHHQK sX6V^^, V^^, sC   4A?D( 4$D 	D%$D%(E*$EE	EEEEc                 H     d fd}t        d      D ]
  } ||        y)zJCheck fork() in main thread works while the main thread is doing an importr   c                    d}d}	 	 t        |       D ]  }t        j                          |dz  } t        j                         }| }t        |      D ]  }t        j
                           	 |rt        j                         j                  |       y # t        |      D ]  }t        j
                           w xY w# t        $ r7 |r3t        j                  dkD  rt        d       t        j                  d        w xY w)Nr   Fr   zRuntimeError in childr   )ranger   r   r$   r%   r   RuntimeErrorr   r(   r)   r'   r+   )levelreleasein_childir2   r   r0   s        r   fork_with_import_lockzDForkTest.test_nested_import_lock_fork.<locals>.fork_with_import_lockE   s    GH+"5\ %((*1% '')C#&wH"7^ +((*+ "NN3N2 #7^ +((*+ *56HHQKs   A B $C &B>>C A D   N)r7   )r0   r=   r9   r   s   `  @r   test_nested_import_lock_forkz%ForkTest.test_nested_import_lock_forkA   s*    	32 1X 	)E!%(	)r   N)__name__
__module____qualname__r4   r?    r   r   r   r      s    (V)r   r   c                  ,    t        j                          y )N)r   reap_childrenrC   r   r   tearDownModulerF   b   s    r   __main__)__doc___impr   r$   r-   r   r   r   unittesttest.fork_waitr   testr   has_fork_supportSkipTestr   rF   r@   mainrC   r   r   <module>rP      st     	  
    #  
(

B
CCJ)x J)Z zHMMO r   