Skip to content
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

Merged
merged 1 commit into from Mar 14, 2024

Conversation

encukou
Copy link
Member

@encukou encukou commented Mar 14, 2024

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.

…ar_caches

Co-Authored-By: Jason R. Coombs <jaraco@jaraco.com>
Copy link
Member

@jaraco jaraco left a 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()
Copy link
Member

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.

Copy link
Member Author

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

@encukou encukou added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Mar 14, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @encukou for commit 7f58006 🤖

If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Mar 14, 2024
@encukou encukou merged commit bae6579 into python:main Mar 14, 2024
47 of 52 checks passed
@encukou encukou deleted the importlib-refleaks branch March 14, 2024 15:47
@encukou encukou added the needs backport to 3.12 bug and security fixes label Mar 14, 2024
@miss-islington-app
Copy link

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 14, 2024
…es in clear_caches (pythonGH-116805)

(cherry picked from commit bae6579)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 14, 2024

GH-116820 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Mar 14, 2024
encukou added a commit that referenced this pull request Mar 14, 2024
…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 <encukou@gmail.com>
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
vstinner pushed a commit to vstinner/cpython that referenced this pull request Mar 20, 2024
…es in clear_caches (pythonGH-116805)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
…es in clear_caches (pythonGH-116805)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
…es in clear_caches (pythonGH-116805)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants