Ñò
‘à"Ic           @   s  d  d k  Z d  d k  l Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k	 Z	 d  d k
 Z
 d e f d „  ƒ  YZ d e i f d „  ƒ  YZ d e	 i f d „  ƒ  YZ d	 e	 i f d
 „  ƒ  YZ d e	 i f d „  ƒ  YZ d „  Z e d j o e ƒ  n d S(   iÿÿÿÿN(   t   verboset   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(    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   __init__   s    c         C   s   |  i  d 7_  d  S(   Ni   (   R   (   R   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   inc   s    c         C   s   |  i  d 8_  d  S(   Ni   (   R   (   R   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   dec   s    c         C   s   |  i  S(   N(   R   (   R   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   get   s    (   t   __name__t
   __module__R   R   R   R   (    (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyR      s   			t
   TestThreadc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s>   t  i i |  d | ƒ| |  _ | |  _ | |  _ | |  _ d  S(   Nt   name(   t	   threadingt   ThreadR   t   testcaset   semat   mutext   nrunning(   R   R   R   R   R   R   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyR      s
    			c         C   sI  t  i  ƒ  d } t o d |  i | d f GHn |  i i i ƒ  zý |  i i i ƒ  zM |  i i ƒ  t o |  i i	 ƒ  Gd GHn |  i
 i |  i i	 ƒ  d j ƒ Wd  QXt i | ƒ t o d G|  i Gd GHn |  i i i ƒ  zV |  i i ƒ  |  i
 i |  i i	 ƒ  d j ƒ t o d	 |  i |  i i	 ƒ  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   t   __exit__t	   __enter__R   R   R   R   R   t   assert_t   timet   sleepR   (   R   t   delay(    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   run!   s&    %(   R   R	   R   R   (    (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyR
      s   	t   ThreadTestsc           B   sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C   sM  d } t  i d d ƒ } t  i ƒ  } t ƒ  } g  } xy t | ƒ D]k } t d | |  | | | ƒ } | i | ƒ |  i | i d  ƒ |  i
 t i d t | ƒ ƒ ƒ | i ƒ  q@ Wt o	 d GHn xa | D]Y } | i | ƒ |  i
 | i ƒ  ƒ |  i | i d ƒ |  i
 t i d t | ƒ ƒ ƒ qÆ Wt o	 d	 GHn |  i | i ƒ  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   failUnlessEqualt   identt   NoneR   t   ret   matcht   reprt   startR    t   joint   is_alivet   failIfEqualt   assertEqualR   (   R   t   NUMTASKSR   R   t
   numrunningt   threadst   it   t(    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_various_ops=   s.    	 	 #	c         C   sf   t  o	 d GHn y t i d ƒ Wn' t i j
 o t  o	 d GHn d  SX|  i ƒ  t i d ƒ d  S(   Ns   with 256kB thread stack size...i   s4   platform does not support changing thread stack sizei    (   R    R   t
   stack_sizet   threadt   errorR1   (   R   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_various_ops_small_stack\   s    		
c         C   sf   t  o	 d GHn y t i d ƒ Wn' t i j
 o t  o	 d GHn d  SX|  i ƒ  t i d ƒ d  S(   Ns   with 1MB thread stack size...i   s4   platform does not support changing thread stack sizei    (   R    R   R2   R3   R4   R1   (   R   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_various_ops_large_stacki   s    		
c         C   s‚   d „  } t  i ƒ  } | i ƒ  t i | | f ƒ } | i ƒ  |  i | t  i j ƒ |  i t t  i | t  i ƒ ƒ t  i | =d  S(   Nc         S   s.   t  i ƒ  } | i ƒ  | i ƒ  |  i ƒ  d  S(   N(   R   R   t   acquiret   release(   R   t   r(    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   fw   s    

(	   R   t   LockR7   R3   t   start_new_threadR   t   _activet
   isinstancet   _DummyThread(   R   R:   R   t   tid(    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_foreign_threadu   s    	

c      	      sÛ  y d d  k  } Wn$ t j
 o t o	 d GHn d  SX| i i } d t f d „  ƒ  Y‰ | i ˆ ƒ } t i ƒ  ‰  t i ƒ  ‰ d t i	 f ‡ ‡ ‡  f d †  ƒ  Y} | ƒ  } t
 | _ | i ƒ  t o	 d GHn t o	 d GHn | | i d ƒ | ƒ } |  i | d	 ƒ t o	 d
 GHn ˆ  i ƒ  t o	 d GHn |  i | i ƒ t o	 d GHn | | i | i ƒ | ƒ } |  i | d ƒ t o	 d GHn ˆ i d d ƒ |  i | i ƒ t o	 d GHn | i o | i ƒ  n d  S(   Niÿÿÿÿs2   test_PyThreadState_SetAsyncExc can't import ctypest   AsyncExcc           B   s   e  Z RS(    (   R   R	   (    (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyRB   •   s   t   Workerc              s   e  Z ‡  ‡ ‡ f d  †  Z RS(   c            so   t  i ƒ  |  _ t |  _ y* x# t o ˆ i ƒ  t i d ƒ q WWn& ˆ j
 o t |  _ ˆ  i ƒ  n Xd  S(   Ngš™™™™™¹?(	   R3   t	   get_identt   idt   Falset   finishedt   Truet   setR   R   (   R   (   t   worker_saw_exceptiont   worker_startedRB   (    s0   /mit/python/lib/python2.6/test/test_threading.pyR   ¢   s    	 
	(   R   R	   R   (    (   RJ   RB   RK   (    s0   /mit/python/lib/python2.6/test/test_threading.pyRC   ¡   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 workeri   s5       waiting for worker to say it caught the exceptiont   timeouti
   s       all OK -- joining worker(   t   ctypest   ImportErrorR    t	   pythonapit   PyThreadState_SetAsyncExct	   Exceptiont	   py_objectR   t   EventR   RH   t   daemonR'   t   c_longR+   t   waitR   RG   RE   R(   (   R   RM   t   set_async_exct	   exceptionRC   R0   t   result(    (   RK   RJ   RB   s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_PyThreadState_SetAsyncExc‹   sN    	%		
			
				
c      	   C   sr   y d d  k  } Wn$ t j
 o t o	 d GHn d  SXd d  k } | i t i d d g ƒ } |  i | d ƒ d  S(   Niÿÿÿÿs6   test_finalize_with_runnning_thread can't import 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*   (   RM   RN   R    t
   subprocesst   callt   syst
   executableR+   (   R   RM   R[   t   rc(    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_finalize_runnning_threadÏ   s    	c         C   sW   d d  k  } | i t i d d g ƒ } |  i | d j d ƒ |  i | d j d ƒ d  S(   Niÿÿÿÿs   -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)
            i   s   interpreted was blockedi    s   Unexpected error(   R[   R\   R]   R^   t   failIft
   failUnless(   R   R[   R_   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_finalize_with_traceö   s
    c      	   C   s«   t  i } t i ƒ  } z xz t d d ƒ D]i } t i | d ƒ t  i d d „  ƒ } | i ƒ  | i ƒ  | ƒ  } |  i	 | | j d | | f ƒ q( WWd  t i | ƒ Xd  S(   Ni   id   i   t   targetc           S   s   d  S(   N(   R#   (    (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   <lambda>  s    s&   #1703448 triggered after %d trials: %s(
   R   t	   enumerateR]   t   getcheckintervalt   xranget   setcheckintervalR   R'   R(   t   assertFalse(   R   t   enumt   old_intervalR/   R0   t   l(    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_enumerate_after_join  s    	 

	c         C   sÈ   d t  f d „  ƒ  Y} | d t ƒ } t i | ƒ } | i i ƒ  ~ |  i d  | ƒ  d d t i	 | ƒ  ƒ ƒ| d t
 ƒ } t i | ƒ } | i i ƒ  ~ |  i d  | ƒ  d d t i	 | ƒ  ƒ ƒd  S(   Nt   RunSelfFunctionc           B   s   e  Z d  „  Z d „  Z RS(   c      	   S   sH   | |  _  t i d |  i d |  f d h |  d 6ƒ |  _ |  i i ƒ  d  S(   NRd   t   argst   kwargst   yet_another(   t   should_raiseR   R   t   _runR3   R'   (   R   Rs   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyR   (  s
    		c         S   s   |  i  o
 t ‚ n d  S(   N(   Rs   t
   SystemExit(   R   t	   other_refRr   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyRt   1  s    
(   R   R	   R   Rt   (    (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyRo   '  s   		Rs   t   msgs   %d references still around(   t   objectRF   t   weakreft   refR3   R(   t   assertEqualsR#   R]   t   getrefcountRH   (   R   Ro   t   cyclic_objectt   weak_cyclic_objectt   raising_cyclic_objectt   weak_raising_cyclic_object(    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_no_refcycle_through_target&  s    (   R   R	   R1   R5   R6   RA   RZ   R`   Rc   Rn   R   (    (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyR   9   s   					D	'		t   ThreadJoinOnShutdownc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s¡   d | } d d  k  } | i t i d | g d | i ƒ} | i ƒ  } | i i ƒ  i d d ƒ } |  i	 | d ƒ |  i
 | d j d	 ƒ |  i | d
 j 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'
        
iÿÿÿÿs   -ct   stdouts   t    s   end of main
end of thread
i   s   interpreter was blockedi    s   Unexpected error(   R[   t   PopenR]   R^   t   PIPERV   Rƒ   t   readt   replaceR+   Ra   Rb   (   R   t   scriptR[   t   pR_   t   data(    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   _run_and_joinH  s    
$c         C   s   d } |  i  | ƒ 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‰   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_1_join_on_shutdownZ  s    	c         C   s8   d d  k  } t | d ƒ p d  Sd } |  i | ƒ d  S(   Niÿÿÿÿt   forksF  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'
            (   t   ost   hasattrRŒ   (   R   R   R‰   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_2_join_in_forked_processg  s
    c         C   sc   d d  k  } t | d ƒ p d  St i d	 j o t i d It i IJd  Sd } |  i | ƒ d  S(
   NiÿÿÿÿRŽ   t   freebsd4t   freebsd5t   freebsd6t   os2emxsB   Skipping test_3_join_in_forked_from_thread due to known OS bugs ons9  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   os2emx(   R   R   R]   t   platformt   stderrRŒ   (   R   R   R‰   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt!   test_3_join_in_forked_from_thready  s    	(   R   R	   RŒ   R   R‘   R˜   (    (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyR‚   F  s   			t   ThreadingExceptionTestsc           B   sP   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   c         C   s-   t  i ƒ  } | i ƒ  |  i t | i ƒ d  S(   N(   R   R   R'   t   assertRaisest   RuntimeError(   R   R3   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_start_thread_againœ  s    
c         C   s#   t  i ƒ  } |  i t | i ƒ d  S(   N(   R   R   Rš   R›   R8   (   R   t   rlock(    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_releasing_unacquired_rlock¡  s    c         C   s#   t  i ƒ  } |  i t | i ƒ d  S(   N(   R   t	   ConditionRš   R›   RV   (   R   t   cond(    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt$   test_waiting_on_unacquired_condition¥  s    c         C   s#   t  i ƒ  } |  i t | i ƒ d  S(   N(   R   RŸ   Rš   R›   t   notify(   R   R    (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt#   test_notify_on_unacquired_condition©  s    c         C   s:   |  i  t t i d d ƒ|  i  t t i d t i ƒd  S(   NR   iÿÿÿÿ(   Rš   t
   ValueErrorR   t	   SemaphoreR]   t   maxint(   R   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt"   test_semaphore_with_negative_value­  s    c         C   s#   t  i ƒ  } |  i t | i ƒ d  S(   N(   R   t   current_threadRš   R›   R(   (   R   R¨   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_joining_current_thread±  s    c         C   s#   t  i ƒ  } |  i t | i ƒ d  S(   N(   R   R   Rš   R›   R(   (   R   R3   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_joining_inactive_threadµ  s    c         C   s3   t  i ƒ  } | i ƒ  |  i t t | d t ƒ d  S(   NRT   (   R   R   R'   Rš   R›   t   setattrRH   (   R   R3   (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   test_daemonize_active_thread¹  s    
(
   R   R	   Rœ   Rž   R¡   R£   R§   R©   Rª   R¬   (    (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyR™   ™  s   							c           C   s   t  i i t t t ƒ d  S(   N(   t   testt   test_supportt   run_unittestR   R‚   R™   (    (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt	   test_main¿  s    t   __main__(   t   test.test_supportR­   R    R   R$   R]   R   R3   R   t   unittestRy   Rx   R   R   R
   t   TestCaseR   R‚   R™   R°   R   (    (    (    s0   /mit/python/lib/python2.6/test/test_threading.pyt   <module>   s$   
 ÿ S&	