From d4592b659f12d7f768c1fc8533c85caf7a84b1e7 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 30 May 2024 15:46:38 -0500 Subject: [PATCH] PYTHON-4455 [v4.7] Improve import time on Windows (#1647) --- 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]