This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients corona10, ronaldoussoren, serhiy.storchaka, vstinner
Date 2021-01-19.11:30:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1611055846.19.0.297118610487.issue42955@roundup.psfhosted.org>
In-reply-to
Content
Myself:
> Having to actually import modules to check if it's a stdlib module or not is not convenient. Many stdlib modules have side effects on import.

The "trace" usecase needs an exhaustive list of all module names. It is even less convenient to have to list all Python modules available on the system only to check modules coming from the stdlib.


Ronald:
> You wouldn't necessarily have to import a module to test, this is something that could be added to importlib.  One (poorly thought out) option is to add sys._stdlib_path with the subsection of sys.path that contains the stdlib, and a function in importlib that returns if a spec is for a stdlib module.

I'm not sure how it would work. I listed different cases which have different constraints:

* From a module name, check if it's part of the stdlib or not
* From a module object, check if it's part of the stdlib or not

For the test on the module name, how would it work with sys._stdlib_path? Should you import the module and then check if its path comes from sys._stdlib_path?


Ronald:
> The disadvantage of this, or for the most part anything but your initial proposal, is that might not be save to use a function in importlib in Py_FatalError.

PR 24254 is a working implementation of my use case: only list third party extension modules on a Python fatal error. It relies on PR 24238 sys.module_names list. The implementation works when called from a signal handler (when faulthandler catch fatal signals like SIGSEGV), it avoids memory allocations on the heap (one of the limits of a signal handler).
History
Date User Action Args
2021-01-19 11:30:46vstinnersetrecipients: + vstinner, ronaldoussoren, serhiy.storchaka, corona10
2021-01-19 11:30:46vstinnersetmessageid: <1611055846.19.0.297118610487.issue42955@roundup.psfhosted.org>
2021-01-19 11:30:46vstinnerlinkissue42955 messages
2021-01-19 11:30:45vstinnercreate