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-67224: Make linecache imports relative to improve startup speed #117501

Merged
merged 2 commits into from Apr 10, 2024

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Apr 3, 2024

Lib/linecache.py Outdated Show resolved Hide resolved
@pablogsal
Copy link
Member Author

Oh man, seems this is complicated because making the import lazy actually fails at shutdown because if the first time this is called its when the interpreter is shutting down, sys.meta_path is None :(

@pablogsal
Copy link
Member Author

Well, I think this should do the trick

Lib/linecache.py Outdated Show resolved Hide resolved
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just a suggestion to reorganize checkcache() import/except ImportError.

Lib/linecache.py Show resolved Hide resolved
Lib/linecache.py Outdated Show resolved Hide resolved
@pablogsal pablogsal merged commit 689ada7 into python:main Apr 10, 2024
31 checks passed
@pablogsal pablogsal deleted the gh-67224-2 branch April 10, 2024 19:09
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this pull request Apr 16, 2024
pythongh-117501 put some code before the docstring, so now it is no longer
recognized as a docstring.
# and slow down the startup sequence.
import os
import sys

"""Update a cache entry and return its list of lines.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lost the docstring because you put the imports before it. Filed #117948 to fix this.

hauntsaninja pushed a commit that referenced this pull request Apr 16, 2024
gh-117501 put some code before the docstring, so now it is no longer
recognized as a docstring.
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
pythongh-117501 put some code before the docstring, so now it is no longer
recognized as a docstring.
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