B
    18\
                 @   sZ   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ZdZ	dZ
G d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   g      ?   c               @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )ForkWaitc             C   s    t  | _i | _d| _g | _d S )Nr   )supportthreading_setup_threading_keyalivestopthreads)self r   R/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Lib/test/fork_wait.pysetUp   s    
zForkWait.setUpc             C   s<   d| _ x| jD ]}|  qW d }| j  tj| j  d S )N   )r	   r
   joinclearr   threading_cleanupr   )r   threadr   r   r   tearDown   s    
zForkWait.tearDownc             C   sB   x<| j s<t | j|< ytt W q tk
r8   Y qX qW d S )N)r	   osgetpidr   timesleep
SHORTSLEEPOSError)r   idr   r   r   f&   s    z
ForkWait.fc             C   sj   x:t dD ].}t|tj\}}||kr*P tdt  q
W | || | |dd|d@ |d? f  d S )N
   r   r   zcause = %d, exit = %d      )ranger   waitpidWNOHANGr   r   r   assertEqual)r   cpidispidstatusr   r   r   	wait_impl.   s    zForkWait.wait_implc       	      C   s  x6t tD ]*}tj| j|fd}|  | j| q
W t	 d }x*t
| jtk rntd |t	 k rFP qFW t| j }| |tt t | j }tjdkrt }nt }|dkrtt d}x(| jD ]}| j| || kr|d7 }qW t| n
| | d S )N)targetargsg      $@g?)Z	unixware7r   r   )r    NUM_THREADS	threadingThreadr   startr
   appendr   	monotoniclenr   r   sortedkeysr#   listcopysysplatformr   Zfork1fork	LONGSLEEP_exitr(   )	r   r%   r   deadlineaZprefork_livesr$   nkeyr   r   r   	test_wait:   s.    





zForkWait.test_waitN)__name__
__module____qualname__r   r   r   r(   r?   r   r   r   r   r      s
   	r   )__doc__r   r6   r   unittestr,   test.supportr   r9   r   r+   TestCaser   r   r   r   r   <module>
   s    