https://github.com/python/cpython/commit/93ac78ac3ee124942bca7492149c3ff0003b6e30
commit: 93ac78ac3ee124942bca7492149c3ff0003b6e30
branch: main
author: Kirill Podoprigora <[email protected]>
committer: markshannon <[email protected]>
date: 2024-02-12T16:05:30Z
summary:
gh-115058: Add ``reset_rare_event_counters`` function in `_testinternalcapi`
(GH-115128)
files:
M Lib/test/test_optimizer.py
M Modules/_testinternalcapi.c
diff --git a/Lib/test/test_optimizer.py b/Lib/test/test_optimizer.py
index c8554c40df4b2d..dfea8be3c6956f 100644
--- a/Lib/test/test_optimizer.py
+++ b/Lib/test/test_optimizer.py
@@ -7,6 +7,9 @@
class TestRareEventCounters(unittest.TestCase):
+ def setUp(self):
+ _testinternalcapi.reset_rare_event_counters()
+
def test_set_class(self):
class A:
pass
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index 0bb739b5398b11..3834f00009cea4 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -1650,6 +1650,20 @@ get_rare_event_counters(PyObject *self, PyObject *type)
);
}
+static PyObject *
+reset_rare_event_counters(PyObject *self, PyObject *Py_UNUSED(type))
+{
+ PyInterpreterState *interp = PyInterpreterState_Get();
+
+ interp->rare_events.set_class = 0;
+ interp->rare_events.set_bases = 0;
+ interp->rare_events.set_eval_frame_func = 0;
+ interp->rare_events.builtin_dict = 0;
+ interp->rare_events.func_modification = 0;
+
+ return Py_None;
+}
+
#ifdef Py_GIL_DISABLED
static PyObject *
@@ -1727,6 +1741,7 @@ static PyMethodDef module_functions[] = {
_TESTINTERNALCAPI_TEST_LONG_NUMBITS_METHODDEF
{"get_type_module_name", get_type_module_name, METH_O},
{"get_rare_event_counters", get_rare_event_counters, METH_NOARGS},
+ {"reset_rare_event_counters", reset_rare_event_counters, METH_NOARGS},
#ifdef Py_GIL_DISABLED
{"py_thread_id", get_py_thread_id, METH_NOARGS},
#endif
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]