diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-01 10:06:18 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-01 10:06:18 (GMT) |
commit | c05e260ecb822431cf5bdcd02b7cb0f4cfc88f6b (patch) | |
tree | fb71efc4179189df04b94d4f0e7d628b2cee62b0 /Lib/test/test_io.py | |
parent | a7726624239367a72f5117700e675d5915a40714 (diff) | |
parent | 263dcd20a374d540c8f0bc07332f1657adf6da83 (diff) | |
download | cpython-c05e260ecb822431cf5bdcd02b7cb0f4cfc88f6b.zip cpython-c05e260ecb822431cf5bdcd02b7cb0f4cfc88f6b.tar.gz cpython-c05e260ecb822431cf5bdcd02b7cb0f4cfc88f6b.tar.bz2 |
Issue #23799: Added test.support.start_threads() for running and cleaning up
multiple threads.
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r-- | Lib/test/test_io.py | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 8754779..9fb85f2 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -1131,11 +1131,8 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests): errors.append(e) raise threads = [threading.Thread(target=f) for x in range(20)] - for t in threads: - t.start() - time.sleep(0.02) # yield - for t in threads: - t.join() + with support.start_threads(threads): + time.sleep(0.02) # yield self.assertFalse(errors, "the following exceptions were caught: %r" % errors) s = b''.join(results) @@ -1454,11 +1451,8 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests): errors.append(e) raise threads = [threading.Thread(target=f) for x in range(20)] - for t in threads: - t.start() - time.sleep(0.02) # yield - for t in threads: - t.join() + with support.start_threads(threads): + time.sleep(0.02) # yield self.assertFalse(errors, "the following exceptions were caught: %r" % errors) bufio.close() @@ -2752,14 +2746,10 @@ class TextIOWrapperTest(unittest.TestCase): text = "Thread%03d\n" % n event.wait() f.write(text) - threads = [threading.Thread(target=lambda n=x: run(n)) + threads = [threading.Thread(target=run, args=(x,)) for x in range(20)] - for t in threads: - t.start() - time.sleep(0.02) - event.set() - for t in threads: - t.join() + with support.start_threads(threads, event.set): + time.sleep(0.02) with self.open(support.TESTFN) as f: content = f.read() for n in range(20): @@ -3493,7 +3483,7 @@ class SignalsTest(unittest.TestCase): self.assertRaises(ZeroDivisionError, wio.write, large_data) finally: signal.alarm(0) - t.join() + t.join() # We got one byte, get another one and check that it isn't a # repeat of the first one. read_results.append(os.read(r, 1)) |