diff options
author | AN Long <aisk@users.noreply.github.com> | 2023-12-07 17:26:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-07 17:26:29 (GMT) |
commit | a955fd68d6451bd42199110c978e99b3d2959db2 (patch) | |
tree | 14eb0414ba650d58b64b4ee21a34ceaf6f65380e /Lib/platform.py | |
parent | b2923a61a10dc2717f4662b590cc9f6d181c6983 (diff) | |
download | cpython-a955fd68d6451bd42199110c978e99b3d2959db2.zip cpython-a955fd68d6451bd42199110c978e99b3d2959db2.tar.gz cpython-a955fd68d6451bd42199110c978e99b3d2959db2.tar.bz2 |
gh-112278: Disable WMI queries on Windows after they time out (GH-112658)
Diffstat (limited to 'Lib/platform.py')
-rwxr-xr-x | Lib/platform.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/Lib/platform.py b/Lib/platform.py index 7bb2220..75aa555 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -118,6 +118,10 @@ import re import sys import functools import itertools +try: + import _wmi +except ImportError: + _wmi = None ### Globals & Constants @@ -312,24 +316,26 @@ def _syscmd_ver(system='', release='', version='', version = _norm_version(version) return system, release, version -try: - import _wmi -except ImportError: - def _wmi_query(*keys): + +def _wmi_query(table, *keys): + global _wmi + if not _wmi: raise OSError("not supported") -else: - def _wmi_query(table, *keys): - table = { - "OS": "Win32_OperatingSystem", - "CPU": "Win32_Processor", - }[table] + table = { + "OS": "Win32_OperatingSystem", + "CPU": "Win32_Processor", + }[table] + try: data = _wmi.exec_query("SELECT {} FROM {}".format( ",".join(keys), table, )).split("\0") - split_data = (i.partition("=") for i in data) - dict_data = {i[0]: i[2] for i in split_data} - return (dict_data[k] for k in keys) + except OSError: + _wmi = None + raise OSError("not supported") + split_data = (i.partition("=") for i in data) + dict_data = {i[0]: i[2] for i in split_data} + return (dict_data[k] for k in keys) _WIN32_CLIENT_RELEASES = [ |