<s> """<STR_LIT>""" <EOL> NUM_THREADS = <NUM_LIT:20> <EOL> FILES_PER_THREAD = <NUM_LIT:50> <EOL> import tempfile <EOL> from test . test_support import start_threads , run_unittest , import_module <EOL> threading = import_module ( '<STR_LIT>' ) <EOL> import unittest <EOL> import StringIO <EOL> from traceback import print_exc <EOL> startEvent = threading . Event ( ) <EOL> class TempFileGreedy ( threading . Thread ) : <EOL> error_count = <NUM_LIT:0> <EOL> ok_count = <NUM_LIT:0> <EOL> def run ( self ) : <EOL> self . errors = StringIO . StringIO ( ) <EOL> startEvent . wait ( ) <EOL> for i in range ( FILES_PER_THREAD ) : <EOL> try : <EOL> f = tempfile . TemporaryFile ( "<STR_LIT>" ) <EOL> f . close ( ) <EOL> except : <EOL> self . error_count += <NUM_LIT:1> <EOL> print_exc ( file = self . errors ) <EOL> else : <EOL> self . ok_count += <NUM_LIT:1> <EOL> class ThreadedTempFileTest ( unittest . TestCase ) : <EOL> def test_main ( self ) : <EOL> threads = [ TempFileGreedy ( ) for i in range ( NUM_THREADS ) ] <EOL> with start_threads ( threads , startEvent . set ) : <EOL> pass <EOL> ok = sum ( t . ok_count for t in threads ) <EOL> errors = [ str ( t . getName ( ) ) + str ( t . errors . getvalue ( ) ) <EOL> for t in threads if t . error_count ] <EOL> msg = "<STR_LIT>" % ( len ( errors ) , ok , <EOL> '<STR_LIT:\n>' . join ( errors ) ) <EOL> self . assertEqual ( errors , [ ] , msg ) <EOL> self . assertEqual ( ok , NUM_THREADS * FILES_PER_THREAD ) <EOL> def test_main ( ) : <EOL> run_unittest ( ThreadedTempFileTest ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
