From 0bf70c4f48d52bdaf92e8756da6f39379093a7fe Mon Sep 17 00:00:00 2001
From: Christian Heimes
Date: Wed, 26 Jan 2022 23:22:27 +0100
Subject: [PATCH 1/2] bpo-40280: Use presence of msvcrt module to detect
Windows
---
Lib/subprocess.py | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 358f49a5f8cd8b9..ad08339b25ddc37 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -65,10 +65,15 @@
# NOTE: We intentionally exclude list2cmdline as it is
# considered an internal implementation detail. issue10838.
-_mswindows = sys.platform == "win32"
+# use presence of msvcrt to detect Windows-like platforms (see bpo-8110)
+try:
+ import msvcrt
+except ModuleNotFoundError:
+ _mswindows = False
+else:
+ _mswindows = True
if _mswindows:
- import msvcrt
import _winapi
from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
From fa8332850f3d42dfcdaf2a30a5a7e8a48bf26a26 Mon Sep 17 00:00:00 2001
From: Christian Heimes
Date: Thu, 27 Jan 2022 08:44:54 +0100
Subject: [PATCH 2/2] Update news entry
---
.../next/Library/2022-01-16-14-07-14.bpo-40280.LtFHfF.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Misc/NEWS.d/next/Library/2022-01-16-14-07-14.bpo-40280.LtFHfF.rst b/Misc/NEWS.d/next/Library/2022-01-16-14-07-14.bpo-40280.LtFHfF.rst
index b7bd7abd80c4293..f5d76760678f6ad 100644
--- a/Misc/NEWS.d/next/Library/2022-01-16-14-07-14.bpo-40280.LtFHfF.rst
+++ b/Misc/NEWS.d/next/Library/2022-01-16-14-07-14.bpo-40280.LtFHfF.rst
@@ -1,4 +1,4 @@
:mod:`subprocess` now imports Windows-specific imports when
-``sys.platform == "win32"`` and POSIX-specific imports on all other
+``msvcrt`` module is available, and POSIX-specific imports on all other
platforms. This gives a clean exception when ``_posixsubprocess`` is not
-available (e.g. Emscripten browser target) and it's slightly faster, too.
+available (e.g. Emscripten browser target).