mirror of
https://github.com/python/cpython.git
synced 2025-08-15 22:30:42 +00:00
bpo-46025: Fix a crash in the atexit module for auto-unregistering functions (GH-30002) (GH-30005)
(cherry picked from commit f0d290d25c
)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
parent
2c2ee83c4d
commit
934a24c641
3 changed files with 21 additions and 1 deletions
|
@ -116,6 +116,21 @@ class GeneralTest(unittest.TestCase):
|
|||
atexit._run_exitfuncs()
|
||||
self.assertEqual(l, [5])
|
||||
|
||||
def test_atexit_with_unregistered_function(self):
|
||||
# See bpo-46025 for more info
|
||||
def func():
|
||||
atexit.unregister(func)
|
||||
1/0
|
||||
atexit.register(func)
|
||||
try:
|
||||
with support.catch_unraisable_exception() as cm:
|
||||
atexit._run_exitfuncs()
|
||||
self.assertEqual(cm.unraisable.object, func)
|
||||
self.assertEqual(cm.unraisable.exc_type, ZeroDivisionError)
|
||||
self.assertEqual(type(cm.unraisable.exc_value), ZeroDivisionError)
|
||||
finally:
|
||||
atexit.unregister(func)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue