René's URL Explorer Experiment


Title: platform: import _wmi on first use · Issue #161513 · python/cpython · GitHub

Open Graph Title: platform: import _wmi on first use · Issue #161513 · python/cpython

X Title: platform: import _wmi on first use · Issue #161513 · python/cpython

Description: Feature or enhancement Lib/platform.py imports _wmi at module level on Windows. _wmi.pyd loads oleaut32.dll and propsys.dll (with _wmi.pyd itself and their dependencies, 7 more images in the process), but WMI is only queried by win32_ver...

Open Graph Description: Feature or enhancement Lib/platform.py imports _wmi at module level on Windows. _wmi.pyd loads oleaut32.dll and propsys.dll (with _wmi.pyd itself and their dependencies, 7 more images in the proces...

X Description: Feature or enhancement Lib/platform.py imports _wmi at module level on Windows. _wmi.pyd loads oleaut32.dll and propsys.dll (with _wmi.pyd itself and their dependencies, 7 more images in the proces...

Opengraph URL: https://github.com/python/cpython/issues/161513

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"platform: import _wmi on first use","articleBody":"### Feature or enhancement\r\n\r\n`Lib/platform.py` imports `_wmi` at module level on Windows. `_wmi.pyd` loads `oleaut32.dll` and `propsys.dll` (with `_wmi.pyd` itself and their dependencies, 7 more images in the process), but WMI is only queried by `win32_ver()`, `version()`, `release()`, `uname()` and the processor/machine helpers. Code that only imports `platform`, or calls `python_version()` or `system()`, pays for it anyway. pytest is one example: it imports `platform` on every run.\r\n\r\nMoving the import into `_wmi_query()` (keeping the \"unavailable\" state so a failed import or query is not retried):\r\n\r\n| 60 runs each, perf_counter around the import | before | after | difference |\r\n|---|---:|---:|---:|\r\n| `import platform` | 18.6 ms | 12.9 ms | −5.5 ms [−6.0, −5.1] |\r\n| `import pytest` | 206 ms | 196 ms | −9.5 ms [−13.6, −4.7] |\r\n\r\n(python-build-standalone 3.14.4, Windows 11 26100.) `win32_ver()`, `uname()`, `machine()`, `version()` and `processor()` return the same values; `test_platform` and `test_wmi` pass.\r\n\r\nThe change, against main (2781ffe1f2):\r\n\r\n```diff\r\ndiff --git a/Lib/platform.py b/Lib/platform.py\r\nindex c87bf2f..375acc2 100644\r\n--- a/Lib/platform.py\r\n+++ b/Lib/platform.py\r\n@@ -114,10 +114,10 @@ import sys\r\n import functools\r\n import itertools\r\n lazy import warnings\r\n-try:\r\n-    import _wmi\r\n-except ImportError:\r\n-    _wmi = None\r\n+# _wmi is imported on first use (see _wmi_query): loading it maps the OLE\r\n+# and property-system DLLs, which most users of this module never need.\r\n+# None means not imported yet, False means unavailable.\r\n+_wmi = None\r\n \r\n ### Globals & Constants\r\n \r\n@@ -332,6 +332,12 @@ def _syscmd_ver(system='', release='', version='',\r\n \r\n def _wmi_query(table, *keys):\r\n     global _wmi\r\n+    if _wmi is None:\r\n+        try:\r\n+            import _wmi as wmi\r\n+        except ImportError:\r\n+            wmi = False\r\n+        _wmi = wmi\r\n     if not _wmi:\r\n         raise OSError(\"not supported\")\r\n     table = {\r\n@@ -344,7 +350,7 @@ def _wmi_query(table, *keys):\r\n             table,\r\n         )).split(\"\\0\")\r\n     except OSError:\r\n-        _wmi = None\r\n+        _wmi = False\r\n         raise OSError(\"not supported\")\r\n     split_data = (i.partition(\"=\") for i in data)\r\n     dict_data = {i[0]: i[2] for i in split_data}\r\n```\r\n\r\n(PEP 810's `lazy import` doesn't fit here because the import sits in `try/except ImportError`.)\r\n\r\nI 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.\r\n\r\n### Has this already been discussed elsewhere?\r\n\r\nThis is a minor feature, which does not need previous discussion elsewhere\r\n\r\n### Links to previous discussion of this feature:\r\n\r\n_No response_\r\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-161543\n* gh-161656\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/azchohfi","@type":"Person","name":"azchohfi"},"datePublished":"2026-11-06T18:43:37Z","url":"https://github.com/python/cpython/issues/161513"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:18161dd0-ec9e-5cf6-4cd2-7d8df7fbd233
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC85E:1CCECA:1427BBC:1AD0D30:6B02039D
html-safe-nonce145a82ea625581b7dc02fb8247fce7cc3da011d9afe4e5617322d8338874a6af
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODVFOjFDQ0VDQToxNDI3QkJDOjFBRDBEMzA6NkIwMjAzOUQiLCJ2aXNpdG9yX2lkIjoiNjMyMTY2ODYyMjgyMTQ5MTYxMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac8ce00ab43bdc5fbb7e9616751c43761a7a36934249d6cf90a1c878cfbeabd9c6
hovercard-subject-tagissue:6248597916
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/161513/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c71a7661bb62fef2dba6895f75da3a2dc34c36aa1100931f50459545782a9297/python/cpython/issues/161513
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c71a7661bb62fef2dba6895f75da3a2dc34c36aa1100931f50459545782a9297/python/cpython/issues/161513
og:image:altFeature or enhancement Lib/platform.py imports _wmi at module level on Windows. _wmi.pyd loads oleaut32.dll and propsys.dll (with _wmi.pyd itself and their dependencies, 7 more images in the proces...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameazchohfi
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/161513#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F161513
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F161513
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/161513
Reloadhttps://github.com/python/cpython/issues/161513
Reloadhttps://github.com/python/cpython/issues/161513
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/161513
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/161513
platform: import _wmi on first usehttps://github.com/python/cpython/issues/161513#top
OS-windowshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22OS-windows%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/azchohfi
azchohfihttps://github.com/azchohfi
on Nov 6, 2026https://github.com/python/cpython/issues/161513#issue-6248597916
2781ffehttps://github.com/python/cpython/commit/2781ffe1f29b0ecf64b011c927ad71df2321b6af
gh-161513: Resolve _wmi lazily in platform #161543https://github.com/python/cpython/pull/161543
gh-161513: Import _wmi lazily in platform #161656https://github.com/python/cpython/pull/161656
NekoAsakurahttps://github.com/NekoAsakura
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
OS-windowshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22OS-windows%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
on Nov 6, 2026https://github.com/python/cpython/issues/161513#event-35389582711
https://github.com/sobolevn
sobolevnhttps://github.com/sobolevn
on Nov 7, 2026https://github.com/python/cpython/issues/161513#issuecomment-6704400121
xixi-boxhttps://github.com/xixi-box
on Nov 7, 2026https://github.com/python/cpython/issues/161513#event-35435703292
pythongh-161513: Resolve _wmi lazily in platform.pyhttps://github.com/xixi-box/cpython/commit/22a4c30188655c8a0970ca78f539e099f7c2e400
pythongh-161513https://github.com/python/cpython/issues/161513
22a4c30https://github.com/xixi-box/cpython/commit/22a4c30188655c8a0970ca78f539e099f7c2e400
pythongh-161513: Resolve _wmi lazily in platform.pyhttps://github.com/xixi-box/cpython/commit/81c0bbedb8dca3710f15ceea33e2ebeb3871696d
pythongh-161513https://github.com/python/cpython/issues/161513
81c0bbehttps://github.com/xixi-box/cpython/commit/81c0bbedb8dca3710f15ceea33e2ebeb3871696d
pythongh-161513: Resolve _wmi lazily in platform.pyhttps://github.com/xixi-box/cpython/commit/4128b12d7f0b5ddcc2bfedfa3fa0c1ef4d453ffd
pythongh-161513https://github.com/python/cpython/issues/161513
4128b12https://github.com/xixi-box/cpython/commit/4128b12d7f0b5ddcc2bfedfa3fa0c1ef4d453ffd
pythongh-161513: address review feedbackhttps://github.com/xixi-box/cpython/commit/07b9781c629f029f5362a4924a4b5506c111e275
pythongh-161513https://github.com/python/cpython/issues/161513
07b9781https://github.com/xixi-box/cpython/commit/07b9781c629f029f5362a4924a4b5506c111e275
pythongh-161513: address review suggestionshttps://github.com/xixi-box/cpython/commit/a10fb8582b80fa9080fa80634110c240b2cc282d
pythongh-161513https://github.com/python/cpython/issues/161513
a10fb85https://github.com/xixi-box/cpython/commit/a10fb8582b80fa9080fa80634110c240b2cc282d
pythongh-161513: trim comments per reviewhttps://github.com/xixi-box/cpython/commit/cb7ba0f6dedc4b7bf27929ab742261b700d5c0c1
pythongh-161513https://github.com/python/cpython/issues/161513
cb7ba0fhttps://github.com/xixi-box/cpython/commit/cb7ba0f6dedc4b7bf27929ab742261b700d5c0c1
pythongh-161513: simplify _wmi_query per reviewhttps://github.com/xixi-box/cpython/commit/7181e56d0758e0d1acc3d0ee61388efdd5ea0309
pythongh-161513https://github.com/python/cpython/issues/161513
7181e56https://github.com/xixi-box/cpython/commit/7181e56d0758e0d1acc3d0ee61388efdd5ea0309
hugovkhttps://github.com/hugovk
on Nov 8, 2026https://github.com/python/cpython/issues/161513#event-35489649054
Improve import time of various stdlib modules #154675https://github.com/python/cpython/issues/154675
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/161513
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/161513
OS-windowshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22OS-windows%22
performancePerformance or resource usagehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22performance%22
stdlibStandard Library Python modules in the Lib/ directoryhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22stdlib%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.