cpython
cpython copied to clipboard
gh-102567: Add -X importtime=2 for logging an importtime message for already-loaded modules
As mentioned in the issue:
While
-X importtimeis incredibly useful for analyzing module import times, by design, it doesn't log anything if an imported module has already been loaded.-X importtime=2would provide additional output for every module that's already been loaded:
The updated example:
>>> import uuid
import time: cached | cached | builtins
import time: cached | cached | linecache
import time: cached | cached | _io
import time: cached | cached | os
import time: cached | cached | sys
import time: cached | cached | enum
import time: 594 | 594 | _uuid
import time: 2428 | 3022 | uuid
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/[email protected]/thread/GEISYQ5BXWGKT33RWF77EOSOMMMFUBUS/
- Issue: gh-102567
Hello! This PR needs to add:
- A
NEWSentry - A
whatsnewentry - A new paragraph in the
Doc/cmdlinefor the-Xoption. - New test case in the
Lib/test/test_cmd_line
Hello! This PR needs to add:
- A
NEWSentry- A
whatsnewentry- A new paragraph in the
Doc/cmdlinefor the-Xoption.- New test case in the
Lib/test/test_cmd_line
Thanks for the quick feedback. I've committed a first pass of 1-3. As for tests: there appear to be no importtime tests (likely due to the fact that any simple implementation would be super noisy as other parts of the interpreter change). Would it be sufficient to do some rudimentary check i.e. import foo then ensure a corresponding foo row appears in the output?
Thanks again!
Hello! This PR needs to add:
- A
NEWSentry- A
whatsnewentry- A new paragraph in the
Doc/cmdlinefor the-Xoption.- New test case in the
Lib/test/test_cmd_lineThanks for the quick feedback. I've committed a first pass of 1-3. As for tests: there appear to be no
importtimetests (likely due to the fact that any simple implementation would be super noisy as other parts of the interpreter change). Would it be sufficient to do some rudimentary check i.e.import foothen ensure a correspondingfoorow appears in the output?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)
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?
@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 😄 However, you should move your changes from whatsnew/3.13.rst to whatsnew/3.14.rst since 3.13 branch is in feature-freeze mode, and this feature will appear only in the 3.14 version.
However, you should move your changes from whatsnew/3.13.rst to whatsnew/3.14.rst since 3.13 branch is in feature-freeze mode, and this feature will appear only in the 3.14 version.
The same applies for the versionchanged directives.
The following commit authors need to sign the Contributor License Agreement:
Ah, we may have to put this on hold. Something's been added that runs (and imports posix) every time you type in the repl, causing it to become nearly unusable.
Apologies for the undue pings, I must have screwed something up with the force push.
Ah, we may have to put this on hold. Something's been added that runs (and imports
posix) every time you type in the repl, causing it to become nearly unusable.
Here's how it can be resolved:
diff --git a/Lib/_pyrepl/unix_console.py b/Lib/_pyrepl/unix_console.py
index c4dedd97d1..db35ee5fb4 100644
--- a/Lib/_pyrepl/unix_console.py
+++ b/Lib/_pyrepl/unix_console.py
@@ -38,6 +38,10 @@
from .unix_eventqueue import EventQueue
from .utils import wlen
+try:
+ import posix
+except ImportError:
+ posix = None
TYPE_CHECKING = False
@@ -545,11 +549,7 @@ def clear(self):
@property
def input_hook(self):
- try:
- import posix
- except ImportError:
- return None
- if posix._is_inputhook_installed():
+ if posix is not None and posix._is_inputhook_installed():
return posix._inputhook
def __enable_bracketed_paste(self) -> None:
Feedback has been implemented, bumping for rearview!
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.
Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.
Apologies for the noise, I had to amend some of the commits with the correct email to pick up the right CLA.