ó
ŠwÛjc           @   sƒ   d  Z  d d l Z d d l Z d d l Z d d l Z d d l j Z e j d ƒ Z d Z	 d Z
 d Z d e j f d „  ƒ  YZ d S(	   sû  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.

While BeOS doesn't officially support fork and native threading in
the same application, the present example should work just fine.  DC
iÿÿÿÿNt	   threadingi   g      à?i   t   ForkWaitc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s.   t  j ƒ  |  _ i  |  _ d |  _ g  |  _ d  S(   Ni    (   t   supportt   threading_setupt   _threading_keyt   alivet   stopt   threads(   t   self(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/fork_wait.pyt   setUp   s    		c         C   sH   d |  _  x |  j D] } | j ƒ  q Wd  } |  j 2t j |  j Œ  d  S(   Ni   (   R   R   t   joint   NoneR   t   threading_cleanupR   (   R   t   thread(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/fork_wait.pyt   tearDown    s    	c         C   sL   xE |  j  sG t j ƒ  |  j | <y t j t ƒ Wq t k
 rC q Xq Wd  S(   N(   R   t   ost   getpidR   t   timet   sleept
   SHORTSLEEPt   IOError(   R   t   id(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/fork_wait.pyt   f)   s    c         C   sŒ   xP t  d ƒ D]B } t j | t j ƒ \ } } | | k r> Pn  t j d t ƒ q W|  j | | ƒ |  j | d d | d @| d ?f ƒ d  S(   Ni
   i   i    s   cause = %d, exit = %diÿ   i   (   t   rangeR   t   waitpidt   WNOHANGR   R   R   t   assertEqual(   R   t   cpidt   it   spidt   status(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/fork_wait.pyt	   wait_impl1   s    c         C   s<  xL t  t ƒ D]> } t j d |  j d | f ƒ } | j ƒ  |  j j | ƒ q Wt j	 t
 ƒ |  j j ƒ  } | j ƒ  |  j | t  t ƒ ƒ |  j j ƒ  } t j d k r¸ t j ƒ  } n t j ƒ  } | d k r+t j	 t
 ƒ d } x5 |  j D]* } |  j | | | k rí | d 7} qí qí Wt j | ƒ n |  j | ƒ d  S(   Nt   targett   argst	   unixware7i    i   (   R"   (   R   t   NUM_THREADSR    t   ThreadR   t   startR   t   appendR   R   t	   LONGSLEEPR   t   keyst   sortR   t   copyt   syst   platformR   t   fork1t   forkt   _exitR   (   R   R   R   t   at   prefork_livesR   t   nt   key(    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/fork_wait.pyt	   test_wait=   s(    

(   t   __name__t
   __module__R	   R   R   R   R4   (    (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/fork_wait.pyR      s
   					(   t   __doc__R   R+   R   t   unittestt   test.supportR   t   import_moduleR    R'   R   R#   t   TestCaseR   (    (    (    s„   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/fork_wait.pyt   <module>   s   0