mς
­fIc           @   s  d  Z  d Z d Z d k Z d k Z d k l Z d k Z d k l	 Z	 d k
 Z
 e i   Z d e i f d     YZ d   Z e d	 j o d k Z d k Z e i e i d
 d  \ Z Z xN e D]F \ Z Z e d j o e e  Z qΓ e d j o e e  Z qΓ qΓ We   n d S(   sΪ  
Create and delete FILES_PER_THREAD temp files (via tempfile.TemporaryFile)
in each of NUM_THREADS threads, recording the number of successes and
failures.  A failure is a bug in tempfile, and may be due to:

+ Trying to create more than one tempfile with the same name.
+ Trying to delete a tempfile that doesn't still exist.
+ Something we've never seen before.

By default, NUM_THREADS == 20 and FILES_PER_THREAD == 50.  This is enough to
create about 150 failures per run under Win98SE in 2.0, and runs pretty
quickly. Guido reports needing to boost FILES_PER_THREAD to 500 before
provoking a 2.0 failure under Linux.  Run the test alone to boost either
via cmdline switches:

-f  FILES_PER_THREAD (int)
-t  NUM_THREADS (int)
i   i2   N(   s
   TestFailed(   s	   print_exct   TempFileGreedyc           B   s   t  Z d Z d Z d   Z RS(   Ni    c         C   s   t  i    |  _ t i   xi t t  D][ } y t i	 d  } | i   Wn& |  i d 7_ t d |  i  q& X|  i d 7_ q& Wd  S(   Ns   w+bi   t   file(   t   StringIOt   selft   errorst
   startEventt   waitt   ranget   FILES_PER_THREADt   it   tempfilet   TemporaryFilet   ft   closet   error_countt	   print_exct   ok_count(   R   R	   R   (    (    t7   /mit/python/lib/python2.4/test/test_threadedtempfile.pyt   run$   s    
 (   t   __name__t
   __module__R   R   R   (    (    (    R   R        s   c          C   sρ   g  } d GHx4 t t  D]& } t   } | i |  | i   q Wd GHt i	   d GHd } }  x^ | D]V } | i   | | i 7} |  | i 7}  | i o" d | i   | i i   f GHqg qg Wd |  | f } | GH|  o t |   n d  S(   Nt   Creatingt   Startingt   Reapingi    s   %s errors:
%ss   Done: errors %d ok %d(   t   threadsR   t   NUM_THREADSR	   R    t   tt   appendt   startR   t   sett   okR   t   joinR   R   t   getNamet   getvaluet   msgt
   TestFailed(   R   R   R	   R   R   R"   (    (    R   t	   test_main1   s,     	

 

&t   __main__i   s   t:f:s   -fs   -t(   t   __doc__R   R   t   threadt	   threadingt   test.test_supportR#   R   t	   tracebackR   R
   t   EventR   t   ThreadR    R$   R   t   syst   getoptt   argvt   optst   argst   ot   vt   int(   R   R
   R1   R    R'   R   R   R   R3   R2   R-   R(   R$   R   R#   R.   R0   (    (    R   t   ?   s*   					 