summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2021-03-29 22:38:51 (GMT)
committerGitHub <noreply@github.com>2021-03-29 22:38:51 (GMT)
commit09b90a037d18f5d4acdf1b14082e57bda78e85d3 (patch)
treedcdab5633c14b61546e3de07c232af3b5c379f83 /Lib
parentc8b5738810516df5722caf049003e9b319427bec (diff)
downloadcpython-09b90a037d18f5d4acdf1b14082e57bda78e85d3.zip
cpython-09b90a037d18f5d4acdf1b14082e57bda78e85d3.tar.gz
cpython-09b90a037d18f5d4acdf1b14082e57bda78e85d3.tar.bz2
bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_sys.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 5b004c2..ee39375 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -1512,6 +1512,21 @@ class SizeofTest(unittest.TestCase):
self.assertIsNone(cur.firstiter)
self.assertIsNone(cur.finalizer)
+ def test_changing_sys_stderr_and_removing_reference(self):
+ # If the default displayhook doesn't take a strong reference
+ # to sys.stderr the following code can crash. See bpo-43660
+ # for more details.
+ code = textwrap.dedent('''
+ import sys
+ class MyStderr:
+ def write(self, s):
+ sys.stderr = None
+ sys.stderr = MyStderr()
+ 1/0
+ ''')
+ rc, out, err = assert_python_failure('-c', code)
+ self.assertEqual(out, b"")
+ self.assertEqual(err, b"")
if __name__ == "__main__":
unittest.main()