Skip to content

Commit 1d6cf42

Browse files
authored
PYTHON-4455 Improve import time on Windows (#1645)
1 parent 8456293 commit 1d6cf42

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

doc/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Changelog
44
Changes in Version 4.8.0
55
-------------------------
66

7+
The handshake metadata for "os.name" on Windows has been simplified to "Windows" to improve import time.
8+
79
.. warning:: PyMongo 4.8 drops support for Python 3.7 and PyPy 3.8: Python 3.8+ or PyPy 3.9+ is now required.
810

911
Changes in Version 4.7.2

pymongo/pool.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,14 @@ def _set_keepalive_times(sock: socket.socket) -> None:
211211
"version": platform.mac_ver()[0],
212212
}
213213
elif sys.platform == "win32":
214+
_ver = sys.getwindowsversion()
214215
_METADATA["os"] = {
215-
"type": platform.system(),
216-
# "Windows XP", "Windows 7", "Windows 10", etc.
217-
"name": " ".join((platform.system(), platform.release())),
218-
"architecture": platform.machine(),
219-
# Windows patch level (e.g. 5.1.2600-SP3)
220-
"version": "-".join(platform.win32_ver()[1:3]),
216+
"type": "Windows",
217+
"name": "Windows",
218+
# Avoid using platform calls, see PYTHON-4455.
219+
"architecture": os.environ.get("PROCESSOR_ARCHITECTURE") or platform.machine(),
220+
# Windows patch level (e.g. 10.0.17763-SP0).
221+
"version": ".".join(map(str, _ver[:3])) + f"-SP{_ver[-1] or '0'}",
221222
}
222223
elif sys.platform.startswith("java"):
223224
_name, _ver, _arch = platform.java_ver()[-1]

0 commit comments

Comments
 (0)