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. Run the test alone to boost either
16 -f FILES_PER_THREAD (int)
20 NUM_THREADS
= 20 # change w/ -t option
21 FILES_PER_THREAD
= 50 # change w/ -f option
23 import thread
# If this fails, we can't test this module
25 from test
.test_support
import TestFailed
27 from traceback
import print_exc
30 startEvent
= threading
.Event()
32 class TempFileGreedy(threading
.Thread
):
37 self
.errors
= StringIO
.StringIO()
39 for i
in range(FILES_PER_THREAD
):
41 f
= tempfile
.TemporaryFile("w+b")
45 print_exc(file=self
.errors
)
53 for i
in range(NUM_THREADS
):
66 errors
+= t
.error_count
68 print '%s errors:\n%s' % (t
.getName(), t
.errors
.getvalue())
70 msg
= "Done: errors %d ok %d" % (errors
, ok
)
76 if __name__
== "__main__":
78 opts
, args
= getopt
.getopt(sys
.argv
[1:], "t:f:")
81 FILES_PER_THREAD
= int(v
)