summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-10-19 22:31:47 (GMT)
committerGitHub <noreply@github.com>2022-10-19 22:31:47 (GMT)
commita8fe4bbd6b78517f640e25697338b9448c4675c1 (patch)
treeb661e5d047c6a0a552c5ccf132cad0df636ba4e1 /Lib
parent4bd63f66cd4f6e8d549f88ae0f4b0106d522b6bb (diff)
downloadcpython-a8fe4bbd6b78517f640e25697338b9448c4675c1.zip
cpython-a8fe4bbd6b78517f640e25697338b9448c4675c1.tar.gz
cpython-a8fe4bbd6b78517f640e25697338b9448c4675c1.tar.bz2
gh-98257: Make _PyEval_SetTrace() reentrant (#98258)
Make sys.setprofile() and sys.settrace() functions reentrant. They can no long fail with: RuntimeError("Cannot install a trace function while another trace function is being installed"). Make _PyEval_SetTrace() and _PyEval_SetProfile() functions reentrant, rather than detecting and rejecting reentrant calls. Only delete the reference to function arguments once the new function is fully set, when a reentrant call is safe. Call also _PySys_Audit() earlier.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_sys_setprofile.py8
-rw-r--r--Lib/test/test_sys_settrace.py8
2 files changed, 4 insertions, 12 deletions
diff --git a/Lib/test/test_sys_setprofile.py b/Lib/test/test_sys_setprofile.py
index 4c3053a..acae433 100644
--- a/Lib/test/test_sys_setprofile.py
+++ b/Lib/test/test_sys_setprofile.py
@@ -437,12 +437,8 @@ class TestEdgeCases(unittest.TestCase):
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)
+ sys.setprofile(foo)
+ self.assertEqual(sys.getprofile(), bar)
def test_same_object(self):
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index 4f577c2..a448f80 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -2796,12 +2796,8 @@ class TestEdgeCases(unittest.TestCase):
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)
+ sys.settrace(foo)
+ self.assertEqual(sys.gettrace(), bar)
def test_same_object(self):