2 Create and delete FILES_PER_THREAD temp files (via tempfile.TemporaryFile)
3 in each of NUM_THREADS threads, recording the number of successes and
4 failures. A failure is a bug in tempfile, and may be due to:
6 + Trying to create more than one tempfile with the same name.
7 + Trying to delete a tempfile that doesn't still exist.
8 + Something we've never seen before.
10 By default, NUM_THREADS == 20 and FILES_PER_THREAD == 50. This is enough to
11 create about 150 failures per run under Win98SE in 2.0, and runs pretty
12 quickly. Guido reports needing to boost FILES_PER_THREAD to 500 before
13 provoking a 2.0 failure under Linux.
19 import thread
# If this fails, we can't test this module
23 from test
.test_support
import threading_setup
, threading_cleanup
, run_unittest
26 from traceback
import print_exc
28 startEvent
= threading
.Event()
30 class TempFileGreedy(threading
.Thread
):
35 self
.errors
= StringIO
.StringIO()
37 for i
in range(FILES_PER_THREAD
):
39 f
= tempfile
.TemporaryFile("w+b")
43 print_exc(file=self
.errors
)
48 class ThreadedTempFileTest(unittest
.TestCase
):
51 thread_info
= threading_setup()
53 for i
in range(NUM_THREADS
):
66 errors
.append(str(t
.getName()) + str(t
.errors
.getvalue()))
68 threading_cleanup(*thread_info
)
70 msg
= "Errors: errors %d ok %d\n%s" % (len(errors
), ok
,
72 self
.assertEquals(errors
, [], msg
)
73 self
.assertEquals(ok
, NUM_THREADS
* FILES_PER_THREAD
)
76 run_unittest(ThreadedTempFileTest
)
78 if __name__
== "__main__":