Skip to content

Commit bb7b164

Browse files
authored
fix: try multiple times to get win32 version to handle flakes (#2814)
The Google tensorflow/jax devinfra team reported that Windows 2022 with Python 3.12.8 has a tendency to be flaky when calling the platform.win32 APIs. I'm very certain I saw similar behavior in the past myself. To fix, just call the APIs a couple times; it seems to fix itself. cc @vam-google
1 parent b7e58d1 commit bb7b164

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ END_UNRELEASED_TEMPLATE
7272
* The `sys._base_executable` value will reflect the underlying interpreter,
7373
not venv interpreter.
7474
* The {obj}`//python/runtime_env_toolchains:all` toolchain now works with it.
75+
* (rules) Better handle flakey platform.win32_ver() calls by calling them
76+
multiple times.
7577

7678
{#v0-0-0-added}
7779
### Added

python/private/python_bootstrap_template.txt

+9-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ def GetWindowsPathWithUNCPrefix(path):
4646
# removed from common Win32 file and directory functions.
4747
# Related doc: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd#enable-long-paths-in-windows-10-version-1607-and-later
4848
import platform
49-
if platform.win32_ver()[1] >= '10.0.14393':
49+
win32_version = None
50+
# Windows 2022 with Python 3.12.8 gives flakey errors, so try a couple times.
51+
for _ in range(3):
52+
try:
53+
win32_version = platform.win32_ver()[1]
54+
break
55+
except (ValueError, KeyError):
56+
pass
57+
if win32_version and win32_version >= '10.0.14393':
5058
return path
5159

5260
# import sysconfig only now to maintain python 2.6 compatibility

python/private/stage2_bootstrap_template.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ def get_windows_path_with_unc_prefix(path):
5858
# Related doc: https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd#enable-long-paths-in-windows-10-version-1607-and-later
5959
import platform
6060

61-
if platform.win32_ver()[1] >= "10.0.14393":
61+
win32_version = None
62+
# Windows 2022 with Python 3.12.8 gives flakey errors, so try a couple times.
63+
for _ in range(3):
64+
try:
65+
win32_version = platform.win32_ver()[1]
66+
break
67+
except (ValueError, KeyError):
68+
pass
69+
if win32_version and win32_version >= '10.0.14393':
6270
return path
6371

6472
# import sysconfig only now to maintain python 2.6 compatibility

0 commit comments

Comments
 (0)