-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-102567: Add -X importtime=2 for logging an importtime message for already-loaded modules #118655
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
base: main
Are you sure you want to change the base?
Conversation
Hello!
|
Thanks for the quick feedback. I've committed a first pass of 1-3. As for tests: there appear to be no Thanks again! |
Yes, it would be sufficient :) |
Also, there's a merge conflict. Can you resolve it? (I can do it myself, but it seems like you have turned off this option) |
Done, just added tests as well |
@Eclips4 who should I ping to get final review? Is it alright if I @ the blamed reviewers? |
I guess @vstinner is the right person to review this 😄 |
The same applies for the |
* imported module has already been loaded. | ||
*/ | ||
if (_PyInterpreterState_GetConfig(interp)->import_time >= 2) { | ||
#define import_level FIND_AND_LOAD(interp).import_level |
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 use a macro here?
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.
I wanted to mirror line 3652 (import_find_and_load
) as closely as possible--since it's only used once I can get rid of the macro if you prefer.
Lib/test/test_cmd_line.py
Outdated
res = assert_python_ok('-X', 'importtime', '-c', code) | ||
self.assertRegex( | ||
res.err.decode("utf-8"), | ||
r"import time: \s*\d+ | \s*\d+ | \s*os" |
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.
It would be nice to check that this line occurs only once.
You can also check that the line with "cached" is not output.
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.
I've added a check to ensure -Ximporttime
does not include =2
output. I added a rudimentary check that -Ximporttime
only shows os
once, though this may be flaky if the structure of the os
module changes.
4f627c5
to
0281267
Compare
Apologies for the noise, I had to amend some of the commits with the correct email to pick up the right CLA. |
80aba50
to
0281267
Compare
Pinging @serhiy-storchaka for re-review; I intend to leave the mypy errors as-is because this import |
Re-pinging for quick review! |
@noahbkim Can you make the CI pass on Windows and macOS? the logs are no more available so I can't see what happened. |
All checks except for mypy should pass. The issue reported by mypy is the following idiom try:
import posix
except ImportError:
posix = None Since this is used pretty widely throughout the standard library, I figured it should be left as is and the warning ignored. I could suppress the warning instead. Update: woah, I lied, something has changed since my last push. I'll fix these failures today. |
You can |
60d94b3
to
2abb3d8
Compare
@AA-Turner merged your changes, happy to do anything else necessary, apologies for the inconvenience of the organization branch. Not sure where your comment went (I saw it in my email), but thanks for helping push this through. |
Thanks @noahbkim, no worries! Are you able to make the changes to We also recently changed our CLA bot, please can you click on the red 'not signed' and ensure everything is up to date? A |
I think I've messed up my branch, I'm going to attempt to squash everything so I can overwrite my commit email correctly. |
Ok, please ping for a review when you've sorted the branch out! If it's easier, feel free to just open a new PR, but a force push here should also work. A |
e53dea1
to
0ed040c
Compare
@AA-Turner I've squashed my changes and given everything a second pass. It looks like I caused some kind of regression in Zeroing I have about 6 tests failing locally, one of which prevents me from compiling with |
0ed040c
to
62d09cd
Compare
except ImportError: | ||
return None | ||
if posix._is_inputhook_installed(): | ||
# avoid inline imports here so the repl doesn't get flooded with import |
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.
A similar change might be needed for WindowsConsole.input_hook
:
cpython/Lib/_pyrepl/windows_console.py
Lines 236 to 243 in b8633f9
@property | |
def input_hook(self): | |
try: | |
import nt | |
except ImportError: | |
return None | |
if nt._is_inputhook_installed(): | |
return nt._inputhook |
As mentioned in the issue:
The updated example (
-Ximporttime=2
):With
-Ximporttime
:Discussion: https://discuss.python.org/t/x-importtrace-to-supplement-x-importtime-for-loaded-modules/23882/5
Prior email chain: https://mail.python.org/archives/list/python-ideas@python.org/thread/GEISYQ5BXWGKT33RWF77EOSOMMMFUBUS/
-X importtime=2
for additional logging when an imported module is already loaded #102567