summaryrefslogtreecommitdiffstats
path: root/Lib/platform.py
diff options
context:
space:
mode:
authorAN Long <aisk@users.noreply.github.com>2023-12-07 17:26:29 (GMT)
committerGitHub <noreply@github.com>2023-12-07 17:26:29 (GMT)
commita955fd68d6451bd42199110c978e99b3d2959db2 (patch)
tree14eb0414ba650d58b64b4ee21a34ceaf6f65380e /Lib/platform.py
parentb2923a61a10dc2717f4662b590cc9f6d181c6983 (diff)
downloadcpython-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-xLib/platform.py32
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 = [