Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Description
Feature or enhancement
Add special handling for-X importtime=2
that provides additional output when already-loaded modules are imported. This will allow users to get a complete picture of runtime imports.
Pitch
While-X importtime
is incredibly useful for analyzing module import times, by design, it doesn't log anything if an imported module has already been loaded.-X importtime=2
would provide additional output for every module that's already been loaded:
>>> import uuidimport time: cached | cached | _ioimport time: cached | cached | _ioimport time: cached | cached | osimport time: cached | cached | sysimport time: cached | cached | enumimport time: cached | cached | _ioimport time: cached | cached | _ioimport time: cached | cached | collectionsimport time: cached | cached | osimport time: cached | cached | reimport time: cached | cached | sysimport time: cached | cached | functoolsimport time: cached | cached | itertoolsimport time: 151 | 151 | _wmiimport time: 18290 | 18440 | platformimport time: 372 | 372 | _uuidimport time: 10955 | 29766 | uuid
In codebases with convoluted/poorly managed import graphs (and consequently, workloads that suffer from long import times), the ability to record all paths to an expensive dependency–not just the first-imported–can help expedite refactoring (and help scale identification of this type of issue). More generally, this flag would provide a more efficient path to tracking runtime dependencies.
The changes required are largely unintrusive: here's my reference implementation: [will relink, need to do some paperwork].
Previous discussion
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/