summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorMario Corchero <mcorcherojim@bloomberg.net>2020-11-12 17:27:44 (GMT)
committerGitHub <noreply@github.com>2020-11-12 17:27:44 (GMT)
commit750c5abf43b7b1627ab59ead237bef4c2314d29e (patch)
treef8ebda9718f8e2b5c7a564a7aaae0e4170639360 /Lib/test/test_threading.py
parentb5cc05bbe681dbe06d5ec6d34318815d1c1ad6c5 (diff)
downloadcpython-750c5abf43b7b1627ab59ead237bef4c2314d29e.zip
cpython-750c5abf43b7b1627ab59ead237bef4c2314d29e.tar.gz
cpython-750c5abf43b7b1627ab59ead237bef4c2314d29e.tar.bz2
bpo-42308: Add threading.__excepthook__ (GH-23218)
Add threading.__excepthook__ to allow retrieving the original value of threading.excepthook in case it is set to a broken or a different value.
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index e0e5406..db440d4 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -1352,6 +1352,27 @@ class ExceptHookTests(BaseTestCase):
'Exception in threading.excepthook:\n')
self.assertEqual(err_str, 'threading_hook failed')
+ def test_original_excepthook(self):
+ def run_thread():
+ with support.captured_output("stderr") as output:
+ thread = ThreadRunFail(name="excepthook thread")
+ thread.start()
+ thread.join()
+ return output.getvalue()
+
+ def threading_hook(args):
+ print("Running a thread failed", file=sys.stderr)
+
+ default_output = run_thread()
+ with support.swap_attr(threading, 'excepthook', threading_hook):
+ custom_hook_output = run_thread()
+ threading.excepthook = threading.__excepthook__
+ recovered_output = run_thread()
+
+ self.assertEqual(default_output, recovered_output)
+ self.assertNotEqual(default_output, custom_hook_output)
+ self.assertEqual(custom_hook_output, "Running a thread failed\n")
+
class TimerTests(BaseTestCase):