mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-94510: Raise on re-entrant calls to sys.setprofile and sys.settrace (GH-94511)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
5f319308a8
commit
40d81fd63b
5 changed files with 105 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
from test import support
|
||||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
import sys
|
||||
import difflib
|
||||
import gc
|
||||
|
@ -2684,5 +2685,43 @@ class TestExtendedArgs(unittest.TestCase):
|
|||
self.assertEqual(counts, {'call': 1, 'line': 2000, 'return': 1})
|
||||
|
||||
|
||||
class TestEdgeCases(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.addCleanup(sys.settrace, sys.gettrace())
|
||||
sys.settrace(None)
|
||||
|
||||
def test_reentrancy(self):
|
||||
def foo(*args):
|
||||
...
|
||||
|
||||
def bar(*args):
|
||||
...
|
||||
|
||||
class A:
|
||||
def __call__(self, *args):
|
||||
pass
|
||||
|
||||
def __del__(self):
|
||||
sys.settrace(bar)
|
||||
|
||||
sys.settrace(A())
|
||||
with support.catch_unraisable_exception() as cm:
|
||||
sys.settrace(foo)
|
||||
self.assertEqual(cm.unraisable.object, A.__del__)
|
||||
self.assertIsInstance(cm.unraisable.exc_value, RuntimeError)
|
||||
|
||||
self.assertEqual(sys.gettrace(), foo)
|
||||
|
||||
|
||||
def test_same_object(self):
|
||||
def foo(*args):
|
||||
...
|
||||
|
||||
sys.settrace(foo)
|
||||
del foo
|
||||
sys.settrace(sys.gettrace())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue