mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
bpo-43660: Fix crash when displaying exceptions with custom values for sys.stderr (GH-25075)
This commit is contained in:
parent
c8b5738810
commit
09b90a037d
3 changed files with 20 additions and 1 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue