@@ -127,6 +127,37 @@ def main():
127127
128128 ''' )
129129
130+ unraisable_hook_code = textwrap .dedent ('''
131+ import sys
132+
133+ class UnraisableHookInitiator:
134+ def __del__(self):
135+ raise Exception('1')
136+
137+ class UnraisableHook:
138+ def __call__(self, *args, **kwds):
139+ print('X', *args)
140+
141+ def __repr__(self):
142+ h = sys.unraisablehook
143+ setattr(sys, 'unraisablehook', sys.__unraisablehook__)
144+ del h
145+ return 'UnraisableHook'
146+
147+ def audit(event, args):
148+ repr(args)
149+
150+ def main():
151+ sys.addaudithook(audit)
152+ setattr(sys, 'unraisablehook', UnraisableHook())
153+ x = UnraisableHookInitiator()
154+ del x
155+
156+ if __name__ == "__main__":
157+ main()
158+
159+ ''' )
160+
130161
131162 def test_print_deleted_stdout (self ):
132163 # print should use strong reference to the stdout.
@@ -244,5 +275,12 @@ def test_input_stderr(self):
244275 self .assertNotIn (b"Segmentation fault" , err )
245276 self .assertNotIn (b"access violation" , err )
246277
278+ def test_errors_unraisablehook (self ):
279+ test_code = self .unraisable_hook_code
280+ rc , _ , err = assert_python_ok ('-c' , test_code )
281+ self .assertEqual (rc , 0 )
282+ self .assertNotIn (b"Segmentation fault" , err )
283+ self .assertNotIn (b"access violation" , err )
284+
247285if __name__ == "__main__" :
248286 unittest .main ()
0 commit comments