ó
ŒwÛjc           @   sL  d  d l  Z d  d l  m Z m Z d  d l m Z d  d l Z d  d l Z d  d l Z e j	 j
 d ƒ Z e j	 j
 d ƒ Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z y d  d l Z Wn e k
 rß e Z n Xd  d l m Z d e f d „  ƒ  YZ d	 e j f d
 „  ƒ  YZ d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j  f d „  ƒ  YZ  d e j! f d „  ƒ  YZ! d e j  f d „  ƒ  YZ" d e j# f d „  ƒ  YZ# d e j$ f d „  ƒ  YZ$ d e j% f d  „  ƒ  YZ% d! „  Z& e' d" k rHe& ƒ  n  d S(#   iÿÿÿÿN(   t   verboset   cpython_only(   t   assert_python_okt   threadt	   threading(   t
   lock_testst   Counterc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s   d |  _  d  S(   Ni    (   t   value(   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/test_threading.pyt   __init__   s    c         C   s   |  j  d 7_  d  S(   Ni   (   R   (   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   inc   s    c         C   s   |  j  d 8_  d  S(   Ni   (   R   (   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   dec   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   get    s    (   t   __name__t
   __module__R	   R
   R   R   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyR      s   			t
   TestThreadc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s>   t  j j |  d | ƒ| |  _ | |  _ | |  _ | |  _ d  S(   Nt   name(   R   t   ThreadR	   t   testcaset   semat   mutext   nrunning(   R   R   R   R   R   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyR	   $   s
    			c         C   s  t  j  ƒ  d } t r/ d |  j | d f GHn  |  j �Ü |  j �I |  j j ƒ  t rk |  j j ƒ  Gd GHn  |  j j	 |  j j ƒ  d ƒ Wd  QXt
 j | ƒ t r³ d G|  j Gd GHn  |  j �R |  j j ƒ  |  j j |  j j ƒ  d ƒ t r
d	 |  j |  j j ƒ  f GHn  Wd  QXWd  QXd  S(
   Ng     ˆÃ@s   task %s will run for %.1f usecg    €„.As   tasks are runningi   t   taskt   donei    s$   %s is finished. %d tasks are running(   t   randomR    R   R   R   R   R
   R   R   t   assertLessEqualt   timet   sleepR   t   assertGreaterEqual(   R   t   delay(    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   run+   s&    

"
(   R   R   R	   R   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyR   #   s   	t   BaseTestCasec           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   t  j j ƒ  |  _ d  S(   N(   t   testt   test_supportt   threading_setupt   _threads(   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   setUpD   s    c         C   s$   t  j j |  j Œ  t  j j ƒ  d  S(   N(   R    R!   t   threading_cleanupR#   t   reap_children(   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   tearDownG   s    (   R   R   R$   R'   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyR   C   s   	t   ThreadTestsc           B   sÅ   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z e j e e d ƒ d ƒ d „  ƒ Z e j e e d ƒ d ƒ d „  ƒ Z d „  Z RS(   c         C   sC  d } t  j d d ƒ } t  j ƒ  } t ƒ  } g  } xm t | ƒ D]_ } t d | |  | | | ƒ } | j | ƒ |  j | j ƒ |  j	 t
 | ƒ d ƒ | j ƒ  q@ Wt r± d GHn  xg | D]_ } | j | ƒ |  j | j ƒ  ƒ |  j | j d ƒ |  j | j ƒ |  j	 t
 | ƒ d ƒ q¸ Wt r)d	 GHn  |  j | j ƒ  d ƒ d  S(
   Ni
   R   i   s   <thread %d>s   ^<TestThread\(.*, initial\)>$s!   waiting for all tasks to completei    s   ^<TestThread\(.*, \w+ -?\d+\)>$s   all tasks done(   R   t   BoundedSemaphoret   RLockR   t   rangeR   t   appendt   assertIsNonet   identt   assertRegexpMatchest   reprt   startR    t   joint   assertFalset   is_alivet   assertNotEqualt   assertIsNotNonet   assertEqualR   (   R   t   NUMTASKSR   R   t
   numrunningt   threadst   it   t(    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_various_opsP   s,    	c            sw   |  j  t j ƒ  j ƒ ‡  ‡ f d †  } t j ƒ  ‰  g  ‰ t j | d ƒ ˆ  j ƒ  |  j  ˆ d ƒ t j ˆ d =d  S(   Nc              s$   ˆ j  t j ƒ  j ƒ ˆ  j ƒ  d  S(   N(   R,   R   t   currentThreadR.   t   set(    (   R   R.   (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   fr   s    i    (    (	   R6   R   R>   R.   t   EventR   t   start_new_threadt   waitt   _active(   R   R@   (    (   R   R.   s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt"   test_ident_of_no_threading_threadso   s    
c         C   s^   t  r d GHn  y t j d ƒ Wn! t j k
 rB |  j d ƒ n X|  j ƒ  t j d ƒ d  S(   Ns   with 256kB thread stack size...i   s4   platform does not support changing thread stack sizei    (   R    R   t
   stack_sizeR   t   errort   skipTestR=   (   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_various_ops_small_stack~   s    
c         C   s^   t  r d GHn  y t j d ƒ Wn! t j k
 rB |  j d ƒ n X|  j ƒ  t j d ƒ d  S(   Ns   with 1MB thread stack size...i   s4   platform does not support changing thread stack sizei    (   R    R   RF   R   RG   RH   R=   (   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_various_ops_large_stack‰   s    
c         C   sy   d „  } t  j ƒ  } | j ƒ  t j | | f ƒ } | j ƒ  |  j | t  j ƒ |  j t  j | t  j ƒ t  j | =d  S(   Nc         S   s   t  j ƒ  |  j ƒ  d  S(   N(   R   t   current_threadt   release(   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyR@   •   s    
(	   R   t   Lockt   acquireR   RB   t   assertInRD   t   assertIsInstancet   _DummyThread(   R   R@   R   t   tid(    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_foreign_thread“   s    	

c   	         sQ  y d d  l  } Wn t k
 r0 |  j d ƒ n X| j j } d t f d „  ƒ  Y‰  | j ˆ  ƒ } t j ƒ  } y) | | j	 | ƒ | ƒ } x
 t
 r• qŒ WWn ˆ  k
 rª n X|  j d ƒ y |  j | d ƒ Wn t k
 rß n Xt j ƒ  ‰ t j ƒ  ‰ d t j f ‡  ‡ ‡ f d †  ƒ  Y} | ƒ  } t
 | _ | j ƒ  t rGd	 GHn  t rUd
 GHn  | | j	 d ƒ | ƒ } |  j | d ƒ t r‹d GHn  ˆ j ƒ  } |  j | ƒ t r²d GHn  |  j | j ƒ t rÐd GHn  | | j	 | j ƒ | ƒ } |  j | d ƒ t r	d GHn  ˆ j d d ƒ |  j | j ƒ t r7d GHn  | j rM| j ƒ  n  d  S(   Niÿÿÿÿs   requires ctypest   AsyncExcc           B   s   e  Z RS(    (   R   R   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRT   ®   s   s   AsyncExc not raisedi   t   Workerc              s   e  Z ‡  ‡ ‡ f d  †  Z RS(   c            sk   t  j ƒ  |  _ t |  _ y( x! t r> ˆ j ƒ  t j d ƒ q WWn$ ˆ  k
 rf t |  _ ˆ j ƒ  n Xd  S(   Ngš™™™™™¹?(	   R   t	   get_identt   idt   Falset   finishedt   TrueR?   R   R   (   R   (   RT   t   worker_saw_exceptiont   worker_started(    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyR   Ð   s    		
	(   R   R   R   (    (   RT   R[   R\   (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRU   Ï   s   s       started worker threads        trying nonsensical thread idi    s,       waiting for worker thread to get starteds"       verifying worker hasn't exiteds2       attempting to raise asynch exception in workers5       waiting for worker to say it caught the exceptiont   timeouti
   s       all OK -- joining worker(   t   ctypest   ImportErrorRH   t	   pythonapit   PyThreadState_SetAsyncExct	   Exceptiont	   py_objectR   RV   t   c_longRZ   t   failR7   t   UnboundLocalErrorR   RA   R   t   daemonR1   R    RC   t
   assertTrueR3   RY   RW   R2   (	   R   R^   t   set_async_exct	   exceptionRR   t   resultRU   R<   t   ret(    (   RT   R[   R\   s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_PyThreadState_SetAsyncExc¦   sd    	%		
	c         C   st   d „  } t  j } | t  _ zH t  j d d „  ƒ } |  j t j | j ƒ |  j | t  j k d ƒ Wd  | t  _ Xd  S(   Nc          W   s   t  j ƒ  ‚ d  S(   N(   R   RG   (   t   args(    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   fail_new_thread   s    t   targetc           S   s   d  S(   N(   t   None(    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   <lambda>  t    s:   Failed to cleanup _limbo map on failure of Thread.start().(	   R   t   _start_new_threadR   t   assertRaisesR   RG   R1   R3   t   _limbo(   R   Ro   Rt   R<   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_limbo_cleanupþ   s    			c         C   s`   y d d  l  } Wn t k
 r0 |  j d ƒ n Xt j t j d d g ƒ } |  j | d ƒ d  S(   Niÿÿÿÿs   requires ctypess   -csK  if 1:
            import ctypes, sys, time, thread

            # This lock is used as a simple event variable.
            ready = thread.allocate_lock()
            ready.acquire()

            # Module globals are cleared before __del__ is run
            # So we save the functions in class dict
            class C:
                ensure = ctypes.pythonapi.PyGILState_Ensure
                release = ctypes.pythonapi.PyGILState_Release
                def __del__(self):
                    state = self.ensure()
                    self.release(state)

            def waitingThread():
                x = C()
                ready.release()
                time.sleep(100)

            thread.start_new_thread(waitingThread, ())
            ready.acquire()  # Be sure the other thread is waiting.
            sys.exit(42)
            i*   (   R^   R_   RH   t
   subprocesst   callt   syst
   executableR7   (   R   R^   t   rc(    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_finalize_runnning_thread  s    c         C   s¨   t  j t j d d g d t  j d t  j ƒ} |  j | j j ƒ |  j | j j ƒ | j	 ƒ  \ } } | j
 } |  j | d k d ƒ |  j | d k d t | ƒ ƒ d  S(	   Ns   -csO  if 1:
            import sys, threading

            # A deadlock-killer, to prevent the
            # testsuite to hang forever
            def killer():
                import os, time
                time.sleep(2)
                print 'program blocked; aborting'
                os._exit(2)
            t = threading.Thread(target=killer)
            t.daemon = True
            t.start()

            # This is the trace function
            def func(frame, event, arg):
                threading.current_thread()
                return func

            sys.settrace(func)
            t   stdoutt   stderri   s   interpreted was blockedi    s   Unexpected error: (   Rx   t   PopenRz   R{   t   PIPEt
   addCleanupR~   t   closeR   t   communicatet
   returncodeR3   Rh   R0   (   R   t   pR~   R   R|   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_finalize_with_trace1  s    			c         C   s°   t  j t j d d g d t  j d t  j ƒ} |  j | j j ƒ |  j | j j ƒ | j	 ƒ  \ } } |  j
 | j ƒ  d ƒ t j d d | t j ƒ j ƒ  } |  j
 | d ƒ d  S(   Ns   -cs¦  if 1:
                import threading
                from time import sleep

                def child():
                    sleep(1)
                    # As a non-daemon thread we SHOULD wake up and nothing
                    # should be torn down yet
                    print "Woke up, sleep function is:", sleep

                threading.Thread(target=child).start()
                raise SystemExit
            R~   R   s5   Woke up, sleep function is: <built-in function sleep>s   ^\[\d+ refs\]Rs   (   Rx   R€   Rz   R{   R�   R‚   R~   Rƒ   R   R„   R7   t   stript   ret   subt	   MULTILINE(   R   R†   R~   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_join_nondaemon_on_shutdownS  s    		!c         C   s¨   t  j } t j ƒ  } z~ xw t d d ƒ D]f } t j | d ƒ t  j d d „  ƒ } | j ƒ  | j ƒ  | ƒ  } |  j	 | | d | | f ƒ q( WWd  t j | ƒ Xd  S(   Ni   id   i   Rp   c           S   s   d  S(   N(   Rq   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRr   w  Rs   s&   #1703448 triggered after %d trials: %s(
   R   t	   enumerateRz   t   getcheckintervalt   xranget   setcheckintervalR   R1   R2   t   assertNotIn(   R   t   enumt   old_intervalR;   R<   t   l(    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_enumerate_after_joinm  s    	

	c         C   sÈ   d t  f d „  ƒ  Y} | d t ƒ } t j | ƒ } | j j ƒ  ~ |  j d  | ƒ  d d t j	 | ƒ  ƒ ƒ| d t
 ƒ } t j | ƒ } | j j ƒ  ~ |  j d  | ƒ  d d t j	 | ƒ  ƒ ƒd  S(   Nt   RunSelfFunctionc           B   s   e  Z d  „  Z d „  Z RS(   c      	   S   sH   | |  _  t j d |  j d |  f d i |  d 6ƒ |  _ |  j j ƒ  d  S(   NRp   Rn   t   kwargst   yet_another(   t   should_raiseR   R   t   _runR   R1   (   R   R™   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyR	   ‚  s
    		c         S   s   |  j  r t ‚ n  d  S(   N(   R™   t
   SystemExit(   R   t	   other_refR˜   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRš   ‹  s    	(   R   R   R	   Rš   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyR–   �  s   		R™   t   msgs   %d references still around(   t   objectRX   t   weakreft   refR   R2   R7   Rq   Rz   t   getrefcountRZ   (   R   R–   t   cyclic_objectt   weak_cyclic_objectt   raising_cyclic_objectt   weak_raising_cyclic_object(    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_no_refcycle_through_target€  s    t   forks   test needs fork()c         C   sB   d } t  d | ƒ \ } } } |  j | d ƒ |  j | d ƒ d  S(   Nsˆ  if 1:
            import thread, threading, os, time

            def background_thread(evt):
                # Creates and registers the _DummyThread instance
                threading.current_thread()
                evt.set()
                time.sleep(10)

            evt = threading.Event()
            thread.start_new_thread(background_thread, (evt,))
            evt.wait()
            assert threading.active_count() == 2, threading.active_count()
            if os.fork() == 0:
                assert threading.active_count() == 1, threading.active_count()
                os._exit(0)
            else:
                os.wait()
        s   -cRs   (   R   R7   (   R   t   codet   _t   outt   err(    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_dummy_thread_after_forkŸ  s    s   needs os.fork()c         C   sÔ   t  j ƒ  } t  j d ƒ z¦ xŸ t d ƒ D]‘ } t j d d „  ƒ } | j ƒ  t j ƒ  } | d k rˆ t j	 | j
 ƒ  r~ d n d ƒ q) | j ƒ  t j | d ƒ \ } } |  j d | ƒ q) WWd  t  j | ƒ Xd  S(   Ni
   i   Rp   c           S   s   d  S(   N(   Rq   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRr   Å  Rs   i    i   (   Rz   RŽ   R�   R+   R   R   R1   t   osR§   t   _exitR4   R2   t   waitpidR7   (   R   R“   R;   R<   t   pidt   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/test_threading.pyt   test_is_alive_after_forkº  s    
"
c         C   s  xt  d d ƒ D]ð } t j | ƒ } g  t  | ƒ D] } t j d | j ƒ ^ q2 } x | D] } | j ƒ  qZ Wx | D] } | j ƒ  qu Wg  t  | ƒ D] } t j d | j ƒ ^ q– } x | D] } | j ƒ  q¾ Wx | D] } | j ƒ  qÙ W|  j t	 | j ƒ q Wd  S(   Ni   i
   Rp   (
   R+   R   R)   R   RN   R1   R2   RL   Ru   t
   ValueError(   R   t   limitt   bsR©   R:   R<   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_BoundedSemaphore_limitÑ  s    ++(   R   R   R=   RE   RI   RJ   RS   Rm   Rw   R}   R‡   RŒ   R•   R¦   t   unittestt
   skipUnlesst   hasattrR­   R¬   R²   R¶   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyR(   L   s   				
		X		$	"			$$t   ThreadJoinOnShutdownc           B   s‹  e  Z d Z d „  Z d „  Z e j e e d ƒ d ƒ e j	 e
 j e k d	 ƒ d
 „  ƒ ƒ Z e j e e d ƒ d ƒ e j	 e
 j e k d	 ƒ d „  ƒ ƒ Z d „  Z e j e e d ƒ d ƒ e j	 e
 j e k d	 ƒ d „  ƒ ƒ Z e j e e d ƒ d ƒ e j	 e
 j e k d	 ƒ d „  ƒ ƒ Z e j e e d ƒ d ƒ e j	 e
 j e k d	 ƒ d „  ƒ ƒ Z e e j	 e d k d ƒ d „  ƒ ƒ Z RS(   t   freebsd4t   freebsd5t   freebsd6t   netbsd5t   os2emxc         C   s¢   d | } t  j t j d | g d t  j ƒ} | j ƒ  } | j j ƒ  j d d ƒ } | j j	 ƒ  |  j
 | d ƒ |  j | d k d ƒ |  j | d	 k d
 ƒ d  S(   Nsó   if 1:
            import sys, os, time, threading

            # a thread, which waits for the main program to terminate
            def joiningfunc(mainthread):
                mainthread.join()
                print 'end of thread'
        
s   -cR~   s   Rs   s   end of main
end of thread
i   s   interpreter was blockedi    s   Unexpected error(   Rx   R€   Rz   R{   R�   RC   R~   t   readt   replaceRƒ   R7   R3   Rh   (   R   t   scriptR†   R|   t   data(    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   _run_and_joinì  s    
$c         C   s   d } |  j  | ƒ d  S(   Nsô   if 1:
            import os
            t = threading.Thread(target=joiningfunc,
                                 args=(threading.current_thread(),))
            t.start()
            time.sleep(0.1)
            print 'end of main'
            (   RÄ   (   R   RÂ   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_1_join_on_shutdownþ  s    	R§   s   needs os.fork()s   due to known OS bugc         C   s   d } |  j  | ƒ d  S(   NsF  if 1:
            childpid = os.fork()
            if childpid != 0:
                os.waitpid(childpid, 0)
                sys.exit(0)

            t = threading.Thread(target=joiningfunc,
                                 args=(threading.current_thread(),))
            t.start()
            print 'end of main'
            (   RÄ   (   R   RÂ   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_2_join_in_forked_process  s    c         C   s   d } |  j  | ƒ d  S(   Ns9  if 1:
            main_thread = threading.current_thread()
            def worker():
                childpid = os.fork()
                if childpid != 0:
                    os.waitpid(childpid, 0)
                    sys.exit(0)

                t = threading.Thread(target=joiningfunc,
                                     args=(main_thread,))
                print 'end of main'
                t.start()
                t.join() # Should not block: main_thread is already stopped

            w = threading.Thread(target=worker)
            w.start()
            (   RÄ   (   R   RÂ   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt!   test_3_join_in_forked_from_thread  s    c         C   sx   t  j t j d | g d t  j ƒ} | j ƒ  } | j j ƒ  j ƒ  j	 d d ƒ } |  j
 | d d ƒ |  j
 | | ƒ d  S(   Ns   -cR~   s   Rs   i    s   Unexpected error(   Rx   R€   Rz   R{   R�   RC   R~   RÀ   t   decodeRÁ   R7   (   R   RÂ   t   expected_outputR†   R|   RÃ   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   assertScriptHasOutput4  s    !c         C   s   d } |  j  | d ƒ d  S(   NsD  if 1:
            import os, time, threading

            finish_join = False
            start_fork = False

            def worker():
                # Wait until this thread's lock is acquired before forking to
                # create the deadlock.
                global finish_join
                while not start_fork:
                    time.sleep(0.01)
                # LOCK HELD: Main thread holds lock across this call.
                childpid = os.fork()
                finish_join = True
                if childpid != 0:
                    # Parent process just waits for child.
                    os.waitpid(childpid, 0)
                # Child process should just return.

            w = threading.Thread(target=worker)

            # Stub out the private condition variable's lock acquire method.
            # This acquires the lock and then waits until the child has forked
            # before returning, which will release the lock soon after.  If
            # someone else tries to fix this test case by acquiring this lock
            # before forking instead of resetting it, the test case will
            # deadlock when it shouldn't.
            condition = w._block
            orig_acquire = condition.acquire
            call_count_lock = threading.Lock()
            call_count = 0
            def my_acquire():
                global call_count
                global start_fork
                orig_acquire()  # LOCK ACQUIRED HERE
                start_fork = True
                if call_count == 0:
                    while not finish_join:
                        time.sleep(0.01)  # WORKER THREAD FORKS HERE
                with call_count_lock:
                    call_count += 1
            condition.acquire = my_acquire

            w.start()
            w.join()
            print('end of main')
            s   end of main
(   RÊ   (   R   RÂ   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt+   test_4_joining_across_fork_in_worker_thread<  s    Fc         C   s    d } d } |  j  | | ƒ d  S(   Ns  if True:
            import os, time, threading

            start_fork = False

            def worker():
                # Wait until the main thread has attempted to join this thread
                # before continuing.
                while not start_fork:
                    time.sleep(0.01)
                childpid = os.fork()
                if childpid != 0:
                    # Parent process just waits for child.
                    (cpid, rc) = os.waitpid(childpid, 0)
                    assert cpid == childpid
                    assert rc == 0
                    print('end of worker thread')
                else:
                    # Child process should just return.
                    pass

            w = threading.Thread(target=worker)

            # Stub out the private condition variable's _release_save method.
            # This releases the condition's lock and flips the global that
            # causes the worker to fork.  At this point, the problematic waiter
            # lock has been acquired once by the waiter and has been put onto
            # the waiters list.
            condition = w._block
            orig_release_save = condition._release_save
            def my_release_save():
                global start_fork
                orig_release_save()
                # Waiter lock held here, condition lock released.
                start_fork = True
            condition._release_save = my_release_save

            w.start()
            w.join()
            print('end of main thread')
            s(   end of worker thread
end of main thread
(   RÊ   (   R   RÂ   t   output(    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt(   test_5_clear_waiter_locks_to_avoid_crash…  s    6c         C   sn   d „  } g  } x= t  d ƒ D]/ } t j d | ƒ } | j | ƒ | j ƒ  q Wx | D] } | j ƒ  qV Wd  S(   Nc          S   s<   t  j ƒ  }  |  d k r+ t  j |  d ƒ n t  j d ƒ d  S(   Ni    (   R­   R§   R¯   R®   (   R°   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   do_fork_and_waitÅ  s    i   Rp   (   R+   R   R   R,   R1   R2   (   R   RÎ   R:   R;   R<   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_reinit_tls_after_fork¿  s    		s   need _testcapi modulec            s�   ‡ f d †  ‰ d „  ‰ ‡  ‡ f d †  ‰  d  ˆ  _ t j ƒ  } t j ˆ ƒ z< t j ˆ ƒ t j ˆ  ƒ x t d ƒ D] } ˆ  ƒ  qv WWd  t j | ƒ Xd  S(   Nc            s   ˆ  S(   N(    (   t   framet   eventt   arg(   t
   noop_trace(    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRÓ   à  s    c           s   s   x	 d Vq Wd  S(   Nt	   generator(    (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRÔ   ä  s    c              s+   ˆ  j  d  k r ˆ ƒ  ˆ  _  n  t ˆ  j  ƒ S(   N(   t   genRq   t   next(    (   t   callbackRÔ   (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyR×   è  s    i   (	   Rq   RÕ   Rz   t   gettracet   settraceR   t	   _testcapit   call_in_temporary_c_threadR+   (   R   t	   old_traceR    (    (   R×   RÔ   RÓ   s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_frame_tstate_tracing×  s    			(   R»   R¼   R½   R¾   R¿   N(   R   R   t   platforms_to_skipRÄ   RÅ   R·   R¸   R¹   R­   t   skipIfRz   t   platformRÆ   RÇ   RÊ   RË   RÍ   RÏ   R   RÚ   Rq   RÝ   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRº   ã  s"    		''	'H'9't   ThreadingExceptionTestsc           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s-   t  j ƒ  } | j ƒ  |  j t | j ƒ d  S(   N(   R   R   R1   Ru   t   RuntimeError(   R   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_start_thread_again  s    
c         C   s#   t  j ƒ  } |  j t | j ƒ d  S(   N(   R   RK   Ru   Râ   R2   (   R   RK   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_joining_current_thread  s    c         C   s#   t  j ƒ  } |  j t | j ƒ d  S(   N(   R   R   Ru   Râ   R2   (   R   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_joining_inactive_thread  s    c         C   s3   t  j ƒ  } | j ƒ  |  j t t | d t ƒ d  S(   NRg   (   R   R   R1   Ru   Râ   t   setattrRZ   (   R   R   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_daemonize_active_thread  s    
c         C   sr   d } t  d | ƒ \ } } } |  j | d ƒ |  j d | ƒ |  j d | ƒ |  j d | ƒ |  j d | ƒ d  S(   NsÉ  if 1:
            import threading
            import time

            running = False
            def run():
                global running
                running = True
                while running:
                    time.sleep(0.01)
                1.0/0.0
            t = threading.Thread(target=run)
            t.start()
            while not running:
                time.sleep(0.01)
            running = False
            t.join()
            s   -cRs   s   Exception in threads"   Traceback (most recent call last):t   ZeroDivisionErrors   Unhandled exception(   R   R7   RO   R‘   (   R   RÂ   R|   Rª   R«   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_print_exception  s    c         C   sr   d } t  d | ƒ \ } } } |  j | d ƒ |  j d | ƒ |  j d | ƒ |  j d | ƒ |  j d | ƒ d  S(   Nsþ  if 1:
            import sys
            import threading
            import time

            running = False
            def run():
                global running
                running = True
                while running:
                    time.sleep(0.01)
                1.0/0.0
            t = threading.Thread(target=run)
            t.start()
            while not running:
                time.sleep(0.01)
            sys.stderr = None
            running = False
            t.join()
            s   -cRs   s   Exception in threads"   Traceback (most recent call last):Rè   s   Unhandled exception(   R   R7   RO   R‘   (   R   RÂ   R|   Rª   R«   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt%   test_print_exception_stderr_is_none_1/  s    c         C   sB   d } t  d | ƒ \ } } } |  j | d ƒ |  j d | ƒ d  S(   Nsþ  if 1:
            import sys
            import threading
            import time

            running = False
            def run():
                global running
                running = True
                while running:
                    time.sleep(0.01)
                1.0/0.0
            sys.stderr = None
            t = threading.Thread(target=run)
            t.start()
            while not running:
                time.sleep(0.01)
            running = False
            t.join()
            s   -cRs   s   Unhandled exception(   R   R7   R‘   (   R   RÂ   R|   Rª   R«   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt%   test_print_exception_stderr_is_none_2K  s    (	   R   R   Rã   Rä   Rå   Rç   Ré   Rê   Rë   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRá      s   						t	   LockTestsc           B   s   e  Z e e j ƒ Z RS(    (   R   R   t   staticmethodR   RM   t   locktype(    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRì   e  s   t
   RLockTestsc           B   s   e  Z e e j ƒ Z RS(    (   R   R   Rí   R   R*   Rî   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRï   h  s   t
   EventTestsc           B   s   e  Z e e j ƒ Z RS(    (   R   R   Rí   R   RA   t	   eventtype(    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRð   k  s   t   ConditionAsRLockTestsc           B   s   e  Z e e j ƒ Z RS(    (   R   R   Rí   R   t	   ConditionRî   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRò   n  s   t   ConditionTestsc           B   s   e  Z e e j ƒ Z RS(    (   R   R   Rí   R   Ró   t   condtype(    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRô   r  s   t   SemaphoreTestsc           B   s   e  Z e e j ƒ Z RS(    (   R   R   Rí   R   t	   Semaphoret   semtype(    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRö   u  s   t   BoundedSemaphoreTestsc           B   s;   e  Z e e j ƒ Z e j e j	 d  k d ƒ d „  ƒ Z
 RS(   t   darwins   test macosx problemc         C   s„   d } d } t  j t j d | g d t  j ƒ} | j ƒ  \ } } | j ƒ  j d d ƒ } |  j | j	 d d ƒ |  j | | ƒ d  S(	   Ns}  if True:
            import threading

            def recurse():
                return recurse()

            def outer():
                try:
                    recurse()
                except RuntimeError:
                    pass

            w = threading.Thread(target=outer)
            w.start()
            w.join()
            print('end of main thread')
            s   end of main thread
s   -cR~   s   Rs   i    s   Unexpected error(
   Rx   R€   Rz   R{   R�   R„   RÈ   RÁ   R7   R…   (   R   RÂ   RÉ   R†   R~   R   RÃ   (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   test_recursion_limit{  s    (   R   R   Rí   R   R)   Rø   R·   R¸   Rz   Rà   Rû   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyRù   x  s   c           C   s/   t  j j t t t t t t t	 t
 t t ƒ
 d  S(   N(   R    R!   t   run_unittestRì   Rï   Rð   Rò   Rô   Rö   Rù   R(   Rº   Rá   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt	   test_main›  s    t   __main__((   t   test.test_supportR    R    R   t   test.script_helperR   R   R‰   Rz   R!   t   import_moduleR   R   R   R·   RŸ   R­   Rx   RÚ   R_   Rq   R   Rž   R   R   R   t   TestCaseR   R(   Rº   Rá   Rì   Rï   Rð   Rò   Rô   Rö   Rù   Rý   R   (    (    (    s‰   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_threading.pyt   <module>   sF   

 	ÿ ˜ÿ e#		