
    <e                        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                     dS dS )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dS )TempFileGreedyr   c                 `   t          j                    | _        t                                           t          t                    D ]g}	 t          j        d          }|	                                 | xj
        dz  c_
        <#  | xj        dz  c_        t          | j                   Y exY wd S )Nzw+b   )file)ioStringIOerrors
startEventwaitrangeFILES_PER_THREADtempfileTemporaryFilecloseok_counterror_countr   )selfifs      1/usr/lib/python3.11/test/test_threadedtempfile.pyrunzTempFileGreedy.run%   s    kmm'(( 	# 	#A#*511			
 "	,  A%  t{++++++	# 	#s   	(B'B+N)__name__
__module____qualname__r   r   r        r   r	   r	   !   s-        KH# # # # #r"   r	   c                       e Zd Zd ZdS )ThreadedTempFileTestc                    d t          t                    D             }t          j        |t          j                  5  	 d d d            n# 1 swxY w Y   t          d |D                       }d |D             }dt          |          |d                    |          fz  }| 	                    |g |           | 	                    |t          t          z             d S )Nc                 *    g | ]}t                      S r!   )r	   ).0r   s     r   
<listcomp>z2ThreadedTempFileTest.test_main.<locals>.<listcomp>5   s    @@@>##@@@r"   c              3   $   K   | ]}|j         V  d S )N)r   r'   ts     r   	<genexpr>z1ThreadedTempFileTest.test_main.<locals>.<genexpr>8   s$      --------r"   c                     g | ]D}|j         	t          |j                  t          |j                                                  z   ES r!   )r   strnamer   getvaluer*   s     r   r(   z2ThreadedTempFileTest.test_main.<locals>.<listcomp>9   sQ     5 5 5am5#af++AH$5$5$7$7 8 88 5 5 5r"   zErrors: errors %d ok %d
%s
)r   NUM_THREADSr   start_threadsr   setsumlenjoinassertEqualr   )r   threadsokr   msgs        r   	test_mainzThreadedTempFileTest.test_main4   s(   @@U;-?-?@@@+GZ^DD 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	--W-----5 5"5 5 5 ,s6{{BIIf/ S)))[+;;<<<<<s   AAAN)r   r   r    r<   r!   r"   r   r$   r$   3   s#        = = = = =r"   r$   __main__)__doc__r   test.supportr   unittestr   	threading	tracebackr   requires_working_threadingr2   r   Eventr   Threadr	   TestCaser$   r   mainr!   r"   r   <module>rH      s     ) ) ) ) ) )  				           +  +4 8 8 8 8  Y_
# # # # #Y% # # #$= = = = =8, = = = zHMOOOOO r"   