-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-116731: libregrtest: Clear inspect & importlib.metadata caches in clear_caches #116805
Conversation
…ar_caches Co-Authored-By: Jason R. Coombs <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole long function makes me wonder if Python shouldn't prescribe a protocol for any module to provide cache cleanup, e.g. a __cache_clean
method. Then there could be a single routine like at the top:
for mod in sys.modules.values():
if hasattr(mod, '__warningregistry__'):
del mod.__warningregistry__
with suppress(AttributeError):
mod.__cache_clean()
Regardless, such a refactor would be out of the scope of this issue.
except KeyError: | ||
pass | ||
else: | ||
importlib_metadata.FastPath.__new__.cache_clear() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not importlib_metadata.MetadataPathFinder().invalidate_caches()
? I feel like the latter is likely to be more robust if new caches are created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, that'd make it too easy to add unbounded caches, like those in #116804. The refleak tests should catch those :)
Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12. |
…es in clear_caches (pythonGH-116805) (cherry picked from commit bae6579) Co-authored-by: Petr Viktorin <[email protected]> Co-authored-by: Jason R. Coombs <[email protected]>
GH-116820 is a backport of this pull request to the 3.12 branch. |
…hes in clear_caches (GH-116805) (GH-116820) gh-116731: libregrtest: Clear inspect & importlib.metadata caches in clear_caches (GH-116805) (cherry picked from commit bae6579) Co-authored-by: Petr Viktorin <[email protected]> Co-authored-by: Jason R. Coombs <[email protected]>
…es in clear_caches (pythonGH-116805) Co-authored-by: Jason R. Coombs <[email protected]>
…es in clear_caches (pythonGH-116805) Co-authored-by: Jason R. Coombs <[email protected]>
…es in clear_caches (pythonGH-116805) Co-authored-by: Jason R. Coombs <[email protected]>
Thanks to @jaraco for investigation (i.e. the hard part of the fix)
Clearing the inspect caches isn't entirely correct -- see #116804.
This PR is a minimal change to get the buildbots green.
test_importlib
started leaking on refleaks #116731