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.
This commit is contained in:
Victor Stinner 2022-10-20 00:31:47 +02:00 committed by GitHub
parent 4bd63f66cd
commit a8fe4bbd6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 56 deletions

View file

@ -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):