-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
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
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() | ||||||
|
nt._supports_virtual_terminal() | |
return nt._supports_virtual_terminal() |
This is missing a return and would never enable virtual terminal anymore.
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
Show resolved
Hide resolved
|
||
* 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 commentThe 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 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.