o
    HXh~                     @   s   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 dZ	dZ
e ZG dd dejZG d	d
 d
ejZedkrBe  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_exc   2   c                   @   s   e Zd ZdZdZdd ZdS )TempFileGreedyr   c                 C   sn   t  | _t  ttD ]'}ztd}|	  W n   |  j
d7  _
t| jd Y q|  jd7  _qd S )Nzw+b   )file)ioStringIOerrors
startEventwaitrangeFILES_PER_THREADtempfileTemporaryFilecloseerror_countr   ok_count)selfif r   D/opt/python-3.10.19/usr/lib/python3.10/test/test_threadedtempfile.pyrun$   s   

zTempFileGreedy.runN)__name__
__module____qualname__r   r   r   r   r   r   r   r       s    r   c                   @   s   e Zd Zdd ZdS )ThreadedTempFileTestc                 C   s   dd t tD }t|tj W d    n1 sw   Y  tdd |D }dd |D }dt||d|f }| 	|g | | 	|tt
  d S )Nc                 S   s   g | ]}t  qS r   )r   ).0r   r   r   r   
<listcomp>4   s    z2ThreadedTempFileTest.test_main.<locals>.<listcomp>c                 s   s    | ]}|j V  qd S )N)r   r   tr   r   r   	<genexpr>7   s    z1ThreadedTempFileTest.test_main.<locals>.<genexpr>c                 S   s*   g | ]}|j rt|jt|j  qS r   )r   strnamer   getvaluer!   r   r   r   r    8   s    zErrors: errors %d ok %d
%s
)r   NUM_THREADSr   Zstart_threadsr   setsumlenjoinZassertEqualr   )r   threadsokr   msgr   r   r   	test_main3   s   
zThreadedTempFileTest.test_mainN)r   r   r   r0   r   r   r   r   r   2   s    r   __main__)__doc__r   Ztest.supportr   Zunittestr	   	threading	tracebackr   r(   r   Eventr   Threadr   ZTestCaser   r   mainr   r   r   r   <module>   s    