-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
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
Changes from 1 commit
58d07be
b081980
ee7a4a0
0226aa1
0b0c56d
f9c07ce
6d50b0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ded modules
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |||||
| import sys | ||||||
|
|
||||||
| import ctypes | ||||||
| import types | ||||||
| from ctypes.wintypes import ( | ||||||
| _COORD, | ||||||
| WORD, | ||||||
|
|
@@ -58,6 +59,12 @@ def __init__(self, err: int | None, descr: str | None = None) -> None: | |||||
| self.err = err | ||||||
| self.descr = descr | ||||||
|
|
||||||
| nt: types.ModuleType | None | ||||||
|
|
||||||
| try: | ||||||
| import nt | ||||||
| except ImportError: | ||||||
| nt = None | ||||||
|
|
||||||
| TYPE_CHECKING = False | ||||||
|
|
||||||
|
|
@@ -121,9 +128,8 @@ class _error(Exception): | |||||
|
|
||||||
| def _supports_vt(): | ||||||
| try: | ||||||
| import nt | ||||||
| return nt._supports_virtual_terminal() | ||||||
| except (ImportError, AttributeError): | ||||||
| nt._supports_virtual_terminal() | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is missing a return and would never enable virtual terminal anymore. |
||||||
| except AttributeError: | ||||||
| return False | ||||||
|
|
||||||
| class WindowsConsole(Console): | ||||||
|
|
@@ -235,11 +241,9 @@ def refresh(self, screen: list[str], c_xy: tuple[int, int]) -> None: | |||||
|
|
||||||
| @property | ||||||
| def input_hook(self): | ||||||
| try: | ||||||
| import nt | ||||||
| except ImportError: | ||||||
| return None | ||||||
| if nt._is_inputhook_installed(): | ||||||
| # avoid inline imports here so the repl doesn't get flooded with import | ||||||
| # logging from -Ximporttime=2 | ||||||
| if nt is not None and nt._is_inputhook_installed(): | ||||||
| return nt._inputhook | ||||||
|
|
||||||
| def __write_changed_line( | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| :option:`-X importtime <-X>` now accepts value ``2``, which indicates that | ||
| an ``importtime`` entry should also be printed if an imported module has | ||
| already been loaded. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,16 +246,32 @@ import_ensure_initialized(PyInterpreterState *interp, PyObject *mod, PyObject *n | |
| rc = _PyModuleSpec_IsInitializing(spec); | ||
| Py_DECREF(spec); | ||
| } | ||
| if (rc <= 0) { | ||
| if (rc == 0) { | ||
| goto done; | ||
| } | ||
| else if (rc < 0) { | ||
| return rc; | ||
| } | ||
|
|
||
| /* Wait until module is done importing. */ | ||
| PyObject *value = PyObject_CallMethodOneArg( | ||
| IMPORTLIB(interp), &_Py_ID(_lock_unlock_module), name); | ||
| if (value == NULL) { | ||
| return -1; | ||
| } | ||
| Py_DECREF(value); | ||
|
|
||
| done: | ||
| /* When -Ximporttime=2, print an import time entry even if an | ||
|
noahbkim marked this conversation as resolved.
Outdated
|
||
| * imported module has already been loaded. | ||
| */ | ||
| if (_PyInterpreterState_GetConfig(interp)->import_time >= 2) { | ||
| #define import_level FIND_AND_LOAD(interp).import_level | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use a macro here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to mirror line 3652 ( |
||
| fprintf(stderr, "import time: cached | cached | %*s\n", | ||
| import_level*2, PyUnicode_AsUTF8(name)); | ||
| #undef import_level | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.