
    ;e8                         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                     dS dS )
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dS )ForkTestc                   	 t          j                    dd	d	fd}t          j        |          }|                                                                  d}t          j                    }	 |s^t                    }|k    rt          j        |           n_t          j
        dk    rt          d           t          j        d           n+|                                 |                     ||	           	 t          j        |t          j                   d
S # t"          $ r Y d
S 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        <                                    t          j        d            t          j        <   t          j                     d S )Ng{Gz?)impacquire_locksysmodulessettimesleeprelease_lock)complete_modulefake_module_nameimport_startedpartial_modules   &/usr/lib/python3.11/test/test_fork1.pyimporterz9ForkTest.test_threaded_import_lock_fork.<locals>.importer   sc    ,:CK()   Jt,;CK()    )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---				gii	  7/00''HX&&&&**@AAAHQKKKK sX666V^,,,,,   V^,,,,   sC   9BD7 D& &
D43D47E)9EE)
E&#E)%E&&E)c                 T     d fd}t          d          D ]} ||           dS )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                     n*# t          |          D ]}t          j                     w xY wnD# t          $ r7 |r3t          j        dk    rt          d           t          j
        d            w xY w|rt          j
                                       |           d S )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^^ + +(****+U7^^ + +(****+ +     **5666HQKKK  #"""NN3N22222s   A A. &B .'BB AC   N)r7   )r0   r=   r9   r   s   `  @r   test_nested_import_lock_forkz%ForkTest.test_nested_import_lock_forkA   s\    	3 	3 	3 	3 	3 	32 1XX 	) 	)E!!%((((	) 	)r   N)__name__
__module____qualname__r4   r?    r   r   r   r      s3        ( ( (V) ) ) ) )r   r   c                  ,    t          j                     d S )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      s        				  



       # # # # # #        D
(
B
C
CCJ) J) J) J) J)x J) J) J)Z   zHMOOOOO r   