From 6419ca72b83c1ba6d9df039c4d5f0e83beb7ba81 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 29 May 2024 20:35:02 -0500 Subject: [PATCH] PYTHON-4455 Improve import time on Windows (#1645) (cherry picked from commit 1d6cf42b819e2a2aae49b54b82ef14c989f97276) --- pymongo/pool.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pymongo/pool.py b/pymongo/pool.py index 6a8cb54b90..50c2a6d3e1 100644 --- a/pymongo/pool.py +++ b/pymongo/pool.py @@ -211,13 +211,14 @@ def _set_keepalive_times(sock: socket.socket) -> None: "version": platform.mac_ver()[0], } elif sys.platform == "win32": + _ver = sys.getwindowsversion() _METADATA["os"] = { - "type": platform.system(), - # "Windows XP", "Windows 7", "Windows 10", etc. - "name": " ".join((platform.system(), platform.release())), - "architecture": platform.machine(), - # Windows patch level (e.g. 5.1.2600-SP3) - "version": "-".join(platform.win32_ver()[1:3]), + "type": "Windows", + "name": "Windows", + # Avoid using platform calls, see PYTHON-4455. + "architecture": os.environ.get("PROCESSOR_ARCHITECTURE") or platform.machine(), + # Windows patch level (e.g. 10.0.17763-SP0). + "version": ".".join(map(str, _ver[:3])) + f"-SP{_ver[-1] or '0'}", } elif sys.platform.startswith("java"): _name, _ver, _arch = platform.java_ver()[-1]