diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-28 18:38:37 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-03-28 18:38:37 (GMT) |
commit | 9db55004a1bc0c0b3efca69dcd577ff58a86ea16 (patch) | |
tree | f54e4634fe90ad07b2a7c7650a2a06d4327fa4ae /Lib/test | |
parent | d7aa5248fb577c7f46d4c0c9b064392bf5c17403 (diff) | |
download | cpython-9db55004a1bc0c0b3efca69dcd577ff58a86ea16.zip cpython-9db55004a1bc0c0b3efca69dcd577ff58a86ea16.tar.gz cpython-9db55004a1bc0c0b3efca69dcd577ff58a86ea16.tar.bz2 |
Make some tests more frienly to MemoryError.
Free memory, unlock hanging threads.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/lock_tests.py | 8 | ||||
-rw-r--r-- | Lib/test/test_gc.py | 10 | ||||
-rw-r--r-- | Lib/test/test_io.py | 15 | ||||
-rw-r--r-- | Lib/test/test_itertools.py | 8 |
4 files changed, 29 insertions, 12 deletions
diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py index 1cbcea2..42a7d82 100644 --- a/Lib/test/lock_tests.py +++ b/Lib/test/lock_tests.py @@ -39,8 +39,12 @@ class Bunch(object): self.finished.append(tid) while not self._can_exit: _wait() - for i in range(n): - start_new_thread(task, ()) + try: + for i in range(n): + start_new_thread(task, ()) + except: + self._can_exit = True + raise def wait_for_started(self): while len(self.started) < self.n: diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index c0be537..c025512 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -402,10 +402,12 @@ class GCTests(unittest.TestCase): for i in range(N_THREADS): t = threading.Thread(target=run_thread) threads.append(t) - for t in threads: - t.start() - time.sleep(1.0) - exit = True + try: + for t in threads: + t.start() + finally: + time.sleep(1.0) + exit = True for t in threads: t.join() finally: diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 5b2bf46..ec19562 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -3514,11 +3514,16 @@ class SignalsTest(unittest.TestCase): # received (forcing a first EINTR in write()). read_results = [] write_finished = False + error = None def _read(): - while not write_finished: - while r in select.select([r], [], [], 1.0)[0]: - s = os.read(r, 1024) - read_results.append(s) + try: + while not write_finished: + while r in select.select([r], [], [], 1.0)[0]: + s = os.read(r, 1024) + read_results.append(s) + except BaseException as exc: + nonlocal error + error = exc t = threading.Thread(target=_read) t.daemon = True def alarm1(sig, frame): @@ -3539,6 +3544,8 @@ class SignalsTest(unittest.TestCase): wio.flush() write_finished = True t.join() + + self.assertIsNone(error) self.assertEqual(N, sum(len(x) for x in read_results)) finally: write_finished = True diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index eb51be4..3aed779 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -1338,8 +1338,12 @@ class TestBasicOps(unittest.TestCase): # Issue 13454: Crash when deleting backward iterator from tee() def test_tee_del_backward(self): forward, backward = tee(repeat(None, 20000000)) - any(forward) # exhaust the iterator - del backward + try: + any(forward) # exhaust the iterator + del backward + except: + del forward, backward + raise def test_StopIteration(self): self.assertRaises(StopIteration, next, zip()) |