mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
[3.11] gh-94510: Raise on re-entrant calls to sys.setprofile and sys.settrace (GH-94511) (GH-94578)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit 40d81fd63b
)
This commit is contained in:
parent
552fc9a9ac
commit
5f4a16b291
5 changed files with 105 additions and 3 deletions
|
@ -2,6 +2,7 @@ import gc
|
|||
import pprint
|
||||
import sys
|
||||
import unittest
|
||||
from test import support
|
||||
|
||||
|
||||
class TestGetProfile(unittest.TestCase):
|
||||
|
@ -415,5 +416,43 @@ def show_events(callable):
|
|||
pprint.pprint(capture_events(callable))
|
||||
|
||||
|
||||
class TestEdgeCases(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.addCleanup(sys.setprofile, sys.getprofile())
|
||||
sys.setprofile(None)
|
||||
|
||||
def test_reentrancy(self):
|
||||
def foo(*args):
|
||||
...
|
||||
|
||||
def bar(*args):
|
||||
...
|
||||
|
||||
class A:
|
||||
def __call__(self, *args):
|
||||
pass
|
||||
|
||||
def __del__(self):
|
||||
sys.setprofile(bar)
|
||||
|
||||
sys.setprofile(A())
|
||||
with support.catch_unraisable_exception() as cm:
|
||||
sys.setprofile(foo)
|
||||
self.assertEqual(cm.unraisable.object, A.__del__)
|
||||
self.assertIsInstance(cm.unraisable.exc_value, RuntimeError)
|
||||
|
||||
self.assertEqual(sys.getprofile(), foo)
|
||||
|
||||
|
||||
def test_same_object(self):
|
||||
def foo(*args):
|
||||
...
|
||||
|
||||
sys.setprofile(foo)
|
||||
del foo
|
||||
sys.setprofile(sys.getprofile())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue