+++ /dev/null
-"""\r
-Create and delete FILES_PER_THREAD temp files (via tempfile.TemporaryFile)\r
-in each of NUM_THREADS threads, recording the number of successes and\r
-failures. A failure is a bug in tempfile, and may be due to:\r
-\r
-+ Trying to create more than one tempfile with the same name.\r
-+ Trying to delete a tempfile that doesn't still exist.\r
-+ Something we've never seen before.\r
-\r
-By default, NUM_THREADS == 20 and FILES_PER_THREAD == 50. This is enough to\r
-create about 150 failures per run under Win98SE in 2.0, and runs pretty\r
-quickly. Guido reports needing to boost FILES_PER_THREAD to 500 before\r
-provoking a 2.0 failure under Linux.\r
-"""\r
-\r
-NUM_THREADS = 20\r
-FILES_PER_THREAD = 50\r
-\r
-import tempfile\r
-\r
-from test.test_support import threading_setup, threading_cleanup, run_unittest, import_module\r
-threading = import_module('threading')\r
-import unittest\r
-import StringIO\r
-from traceback import print_exc\r
-\r
-startEvent = threading.Event()\r
-\r
-class TempFileGreedy(threading.Thread):\r
- error_count = 0\r
- ok_count = 0\r
-\r
- def run(self):\r
- self.errors = StringIO.StringIO()\r
- startEvent.wait()\r
- for i in range(FILES_PER_THREAD):\r
- try:\r
- f = tempfile.TemporaryFile("w+b")\r
- f.close()\r
- except:\r
- self.error_count += 1\r
- print_exc(file=self.errors)\r
- else:\r
- self.ok_count += 1\r
-\r
-\r
-class ThreadedTempFileTest(unittest.TestCase):\r
- def test_main(self):\r
- threads = []\r
- thread_info = threading_setup()\r
-\r
- for i in range(NUM_THREADS):\r
- t = TempFileGreedy()\r
- threads.append(t)\r
- t.start()\r
-\r
- startEvent.set()\r
-\r
- ok = 0\r
- errors = []\r
- for t in threads:\r
- t.join()\r
- ok += t.ok_count\r
- if t.error_count:\r
- errors.append(str(t.getName()) + str(t.errors.getvalue()))\r
-\r
- threading_cleanup(*thread_info)\r
-\r
- msg = "Errors: errors %d ok %d\n%s" % (len(errors), ok,\r
- '\n'.join(errors))\r
- self.assertEqual(errors, [], msg)\r
- self.assertEqual(ok, NUM_THREADS * FILES_PER_THREAD)\r
-\r
-def test_main():\r
- run_unittest(ThreadedTempFileTest)\r
-\r
-if __name__ == "__main__":\r
- test_main()\r