diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-09-21 19:08:00 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-09-21 19:08:00 (GMT) |
commit | 91943460b54c20fda330d78a6b8d7643ef838b4e (patch) | |
tree | 16a463cf38352fca8dd2ae7c9e48ad9a6b85a9a5 /Lib/test/test_threading.py | |
parent | 3e46d7cba27f5636ba16c37651ba4ff6371e1a50 (diff) | |
download | cpython-91943460b54c20fda330d78a6b8d7643ef838b4e.zip cpython-91943460b54c20fda330d78a6b8d7643ef838b4e.tar.gz cpython-91943460b54c20fda330d78a6b8d7643ef838b4e.tar.bz2 |
Issue #22423: Unhandled exception in thread no longer causes unhandled
AttributeError when sys.stderr is None.
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r-- | Lib/test/test_threading.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index 86c953f..ac41f2d 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -829,6 +829,85 @@ class ThreadingExceptionTests(BaseTestCase): thread.start() self.assertRaises(RuntimeError, setattr, thread, "daemon", True) + def test_print_exception(self): + script = r"""if 1: + import threading + import time + + running = False + def run(): + global running + running = True + while running: + time.sleep(0.01) + 1/0 + t = threading.Thread(target=run) + t.start() + while not running: + time.sleep(0.01) + running = False + t.join() + """ + rc, out, err = assert_python_ok("-c", script) + self.assertEqual(out, '') + self.assertIn("Exception in thread", err) + self.assertIn("Traceback (most recent call last):", err) + self.assertIn("ZeroDivisionError", err) + self.assertNotIn("Unhandled exception", err) + + def test_print_exception_stderr_is_none_1(self): + script = r"""if 1: + import sys + import threading + import time + + running = False + def run(): + global running + running = True + while running: + time.sleep(0.01) + 1/0 + t = threading.Thread(target=run) + t.start() + while not running: + time.sleep(0.01) + sys.stderr = None + running = False + t.join() + """ + rc, out, err = assert_python_ok("-c", script) + self.assertEqual(out, '') + self.assertIn("Exception in thread", err) + self.assertIn("Traceback (most recent call last):", err) + self.assertIn("ZeroDivisionError", err) + self.assertNotIn("Unhandled exception", err) + + def test_print_exception_stderr_is_none_2(self): + script = r"""if 1: + import sys + import threading + import time + + running = False + def run(): + global running + running = True + while running: + time.sleep(0.01) + 1/0 + sys.stderr = None + t = threading.Thread(target=run) + t.start() + while not running: + time.sleep(0.01) + running = False + t.join() + """ + rc, out, err = assert_python_ok("-c", script) + self.assertEqual(out, '') + self.assertNotIn("Unhandled exception", err) + class LockTests(lock_tests.LockTests): locktype = staticmethod(threading.Lock) |