GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing github.com — platform: import _wmi on first use · Issue #161513 · python/cpython Open Labels OS-windowsperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement DescriptionFeature or enhancement
Moving the import into
(python-build-standalone 3.14.4, Windows 11 26100.) The change, against main (2781ffe): diff --git a/Lib/platform.py b/Lib/platform.py index c87bf2f..375acc2 100644 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -114,10 +114,10 @@ import sys import functools import itertools lazy import warnings -try: - import _wmi -except ImportError: - _wmi = None +# _wmi is imported on first use (see _wmi_query): loading it maps the OLE +# and property-system DLLs, which most users of this module never need. +# None means not imported yet, False means unavailable. +_wmi = None ### Globals & Constants @@ -332,6 +332,12 @@ def _syscmd_ver(system='', release='', version='', def _wmi_query(table, *keys): global _wmi + if _wmi is None: + try: + import _wmi as wmi + except ImportError: + wmi = False + _wmi = wmi if not _wmi: raise OSError("not supported") table = { @@ -344,7 +350,7 @@ def _wmi_query(table, *keys): table, )).split("\0") except OSError: - _wmi = None + _wmi = False raise OSError("not supported") split_data = (i.partition("=") for i in data) dict_data = {i[0]: i[2] for i in split_data} (PEP 810's I used GitHub Copilot (Claude Opus 5.5 model) to trace this, build and time the prototype, and draft this issue. The measurements were run on my machine. Has this already been discussed elsewhere?This is a minor feature, which does not need previous discussion elsewhere Links to previous discussion of this feature:No response Linked PRsActivity
MetadataMetadataAssigneesLabelsOS-windowsperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement ProjectsMilestoneRelationshipsDevelopmentIssue actions | ||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |