
    ;e                     |    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mZ ddlm	Z	 dZ
dZdZ G d d	ej                  ZdS )
ar  This test case provides support for checking forking and wait behavior.

To test different wait behavior, override the wait_impl method.

We want fork1() semantics -- only the forking thread survives in the
child after a fork().

On some systems (e.g. Solaris without posix threads) we find that all
active threads survive in the child after a fork(); this is an error.
    N)support)threading_helper   g      ?   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )ForkWaitc                 `    t          j                    | _        i | _        d| _        g | _        d S )Nr   )r   threading_setup_threading_keyalivestopthreads)selfs    %/usr/lib/python3.11/test/fork_wait.pysetUpzForkWait.setUp   s,    .>@@
	    c                     d| _         | j        D ]}|                                 d }| j                                         t	          j        | j          d S )N   )r   r   joinclearr   threading_cleanupr   )r   threads     r   tearDownzForkWait.tearDown   sY    	l 	 	FKKMMMM*D,?@@@@r   c                     | j         sOt          j                    | j        |<   	 t	          j        t                     n# t          $ r Y nw xY w| j         Md S d S )N)r   osgetpidr   timesleep
SHORTSLEEPOSError)r   ids     r   fz
ForkWait.f'   su    ) 	Y[[DJrN
:&&&&   	 ) 	 	 	 	 	s   > 
A
Ac                2    t          j        ||           d S )Nexitcode)r   wait_process)r   cpidr%   s      r   	wait_implzForkWait.wait_impl/   s    TH555555r   c                    t          t                    D ]L}t          j        | j        |f          }|                                 | j                            |           Mt          j	                    t          j        z   }t          | j                  t          k     rIt          j        d           |t          j	                    k     rnt          | j                  t          k     It          | j                                                  }|                     |t%          t          t                                         | j                                        }t(          j        dv rt-          j                    }nt-          j                    }|dk    rWt          j        t2                     d}| j        D ]}| j        |         ||         k    r|dz  }t-          j        |           d S |                     |d           d S )N)targetargsg?)	unixware7r   r   r$   )rangeNUM_THREADS	threadingThreadr"   startr   appendr   	monotonicr   SHORT_TIMEOUTlenr   r   sortedkeysassertEquallistcopysysplatformr   fork1fork	LONGSLEEP_exitr(   )	r   ir   deadlineaprefork_livesr'   nkeys	            r   	test_waitzForkWait.test_wait2   s   {## 	( 	(A%TV1$???FLLNNNL'''' >##g&;;$*oo++JsOOO$.**** $*oo++
 4:??$$%%D{!3!344555
))<=((8::DD799D199Jy!!!Az  :c?mC&888FAHQKKKKK NN4!N,,,,,r   N)__name__
__module____qualname__r   r   r"   r(   rG    r   r   r   r      sb          A A A  6 6 6!- !- !- !- !-r   r   )__doc__r   r;   r   unittestr/   testr   test.supportr   r?   r   r.   TestCaser   rK   r   r   <module>rQ      s   	 	                           ) ) ) ) ) ) 	
=- =- =- =- =-x  =- =- =- =- =-r   