diff options
author | Brandt Bucher <brandtbucher@microsoft.com> | 2024-02-12 09:04:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-12 09:04:36 (GMT) |
commit | 235cacff81931a68e8c400bb3919ae6e55462fb5 (patch) | |
tree | 2f4c7d4a8d0f2e0bbdad8e28560609a2aab27bf5 /Python/sysmodule.c | |
parent | 54bde5dcc3c04c4ddebcc9df2904ab325fa0b486 (diff) | |
download | cpython-235cacff81931a68e8c400bb3919ae6e55462fb5.zip cpython-235cacff81931a68e8c400bb3919ae6e55462fb5.tar.gz cpython-235cacff81931a68e8c400bb3919ae6e55462fb5.tar.bz2 |
GH-114695: Add `sys._clear_internal_caches` (GH-115152)
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 437d7f8..69b6d88 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2127,6 +2127,22 @@ sys__clear_type_cache_impl(PyObject *module) Py_RETURN_NONE; } +/*[clinic input] +sys._clear_internal_caches + +Clear all internal performance-related caches. +[clinic start generated code]*/ + +static PyObject * +sys__clear_internal_caches_impl(PyObject *module) +/*[clinic end generated code: output=0ee128670a4966d6 input=253e741ca744f6e8]*/ +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + _Py_Executors_InvalidateAll(interp); + PyType_ClearCache(); + Py_RETURN_NONE; +} + /* Note that, for now, we do not have a per-interpreter equivalent for sys.is_finalizing(). */ @@ -2461,6 +2477,7 @@ static PyMethodDef sys_methods[] = { {"audit", _PyCFunction_CAST(sys_audit), METH_FASTCALL, audit_doc }, {"breakpointhook", _PyCFunction_CAST(sys_breakpointhook), METH_FASTCALL | METH_KEYWORDS, breakpointhook_doc}, + SYS__CLEAR_INTERNAL_CACHES_METHODDEF SYS__CLEAR_TYPE_CACHE_METHODDEF SYS__CURRENT_FRAMES_METHODDEF SYS__CURRENT_EXCEPTIONS_METHODDEF |