a zej@sdZddlZddlmZddlZddlZddlZddlmZdZ dZ e Z Gdddej ZGd d d ejZed kredS) 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) start_threads) print_exc2c@seZdZdZdZddZdS)TempFileGreedyrcCspt|_tttD]P}ztd}| Wn&|j d7_ t |jdYq0|j d7_ qdS)Nzw+b)file) ioStringIOerrors startEventwaitrangeFILES_PER_THREADtempfile TemporaryFileclose error_countrok_count)selfifrN/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_threadedtempfile.pyrun$s    zTempFileGreedy.runN)__name__ __module__ __qualname__rrrrrrrr src@seZdZddZdS)ThreadedTempFileTestcCsddttD}t|tjWdn1s40Ytdd|D}dd|D}dt||d|f}||g|||tt dS)NcSsg|] }tqSr)r).0rrrr 4z2ThreadedTempFileTest.test_main..css|] }|jVqdS)N)rrtrrr 7r!z1ThreadedTempFileTest.test_main..cSs*g|]"}|jrt|jt|jqSr)rstrnamer getvaluer"rrrr 8szErrors: errors %d ok %d %s ) r NUM_THREADSrr setsumlenjoinZ assertEqualr)rthreadsokr msgrrr test_main3s zThreadedTempFileTest.test_mainN)rrrr1rrrrr2sr__main__)__doc__rZ test.supportrZunittestr threading tracebackrr)rEventr ThreadrZTestCaserrmainrrrrs