
    daf                        d Z ddlZddlmZ ddlZddlZddlZddlmZ  ej                  d       dZ
dZ ej                         Z G d	 d
ej                        Z G d dej                         Zedk(  r ej&                          yy)an  
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.
    N)threading_helper)	print_excT)module   2   c                       e Zd ZdZdZd Zy)TempFileGreedyr   c                 `   t        j                         | _        t        j	                          t        t              D ]=  }	 t        j                  d      }|j                          | xj                  dz  c_
        ? y #  | xj                  dz  c_        t        | j                         Y pxY w)Nzw+b   )file)ioStringIOerrors
startEventwaitrangeFILES_PER_THREADtempfileTemporaryFilecloseok_counterror_countr   )selfifs      5/root/Python-3.12.4/Lib/test/test_threadedtempfile.pyrunzTempFileGreedy.run%   s    kkm'( 	#A#**51	
 "	#,  A% t{{+s   %A>>-B-N)__name__
__module____qualname__r   r   r        r   r	   r	   !   s    KH#r"   r	   c                       e Zd Zd Zy)ThreadedTempFileTestc                 <   t        t              D cg c]  }t                }}t        j                  |t
        j                        5  	 d d d        t        d |D              }|D cg c]G  }|j                  r9t        |j                        t        |j                  j                               z   I }}dt        |      |dj                  |      fz  }| j                  |g |       | j                  |t        t         z         y c c}w # 1 sw Y   xY wc c}w )Nc              3   4   K   | ]  }|j                     y w)N)r   ).0ts     r   	<genexpr>z1ThreadedTempFileTest.test_main.<locals>.<genexpr>8   s     --s   zErrors: errors %d ok %d
%s
)r   NUM_THREADSr	   r   start_threadsr   setsumr   strnamer   getvaluelenjoinassertEqualr   )r   r   threadsokr(   r   msgs          r   	test_mainzThreadedTempFileTest.test_main4   s    -2;-?@>#@@++GZ^^D 		-W--"5amm aff+AHH$5$5$7 88 5 5 ,s6{BIIf/ S)[+;;< A	 	5s   D	D)ADDN)r   r   r    r8   r!   r"   r   r$   r$   3   s    =r"   r$   __main__)__doc__r   test.supportr   unittestr   	threading	tracebackr   requires_working_threadingr+   r   Eventr   Threadr	   TestCaser$   r   mainr!   r"   r   <module>rD      s     )  	   +  + +4 8  Y__
#Y%% #$=8,, = zHMMO r"   