diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-01 10:01:14 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-01 10:01:14 (GMT) |
commit | 263dcd20a374d540c8f0bc07332f1657adf6da83 (patch) | |
tree | c44955a3ff494353583163d4634cae512e7836dc /Lib/test/test_io.py | |
parent | 8218bd4caf683ee98c450a093bf171dbca6c4849 (diff) | |
download | cpython-263dcd20a374d540c8f0bc07332f1657adf6da83.zip cpython-263dcd20a374d540c8f0bc07332f1657adf6da83.tar.gz cpython-263dcd20a374d540c8f0bc07332f1657adf6da83.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 | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index ec19562..95277d9 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -1070,11 +1070,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) @@ -1393,11 +1390,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() @@ -2691,14 +2685,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): @@ -3402,11 +3392,11 @@ class SignalsTest(unittest.TestCase): # handlers, which in this case will invoke alarm_interrupt(). signal.alarm(1) try: - self.assertRaises(ZeroDivisionError, - wio.write, item * (support.PIPE_MAX_SIZE // len(item) + 1)) + with self.assertRaises(ZeroDivisionError): + wio.write(item * (support.PIPE_MAX_SIZE // len(item) + 1)) 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)) |