summaryrefslogtreecommitdiff
path: root/Lib/test/test_thread.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-04-02 11:15:17 -0400
committerBenjamin Peterson <benjamin@python.org>2012-04-02 11:15:17 -0400
commitf73813a8bbb55ac725720f4d3839b51f992f1f3f (patch)
tree472c83f2ff6a7a1f1f93e3f2dedfe86cd1f24ae2 /Lib/test/test_thread.py
parentfe9417726c8d2a15ae11f553ae521c3ba6dfc6b7 (diff)
downloadcpython-git-f73813a8bbb55ac725720f4d3839b51f992f1f3f.tar.gz
prevent writing to stderr from messing up the exception state (closes #14474)
Diffstat (limited to 'Lib/test/test_thread.py')
-rw-r--r--Lib/test/test_thread.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py
index 544e70d2fd..387fa030ce 100644
--- a/Lib/test/test_thread.py
+++ b/Lib/test/test_thread.py
@@ -130,6 +130,30 @@ class ThreadRunningTests(BasicThreadTest):
time.sleep(0.01)
self.assertEqual(thread._count(), orig)
+ def test_save_exception_state_on_error(self):
+ # See issue #14474
+ def task():
+ started.release()
+ sys.stderr = stderr
+ raise SyntaxError
+ def mywrite(self, *args):
+ try:
+ raise ValueError
+ except ValueError:
+ pass
+ real_write(self, *args)
+ c = thread._count()
+ started = thread.allocate_lock()
+ with test_support.captured_output("stderr") as stderr:
+ real_write = stderr.write
+ stderr.write = mywrite
+ started.acquire()
+ thread.start_new_thread(task, ())
+ started.acquire()
+ while thread._count() > c:
+ pass
+ self.assertIn("Traceback", stderr.getvalue())
+
class Barrier:
def __init__(self, num_threads):