]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40280: Use presence of msvcrt module to detect Windows (GH-30930)
authorChristian Heimes <christian@python.org>
Thu, 27 Jan 2022 09:57:43 +0000 (11:57 +0200)
committerGitHub <noreply@github.com>
Thu, 27 Jan 2022 09:57:43 +0000 (01:57 -0800)
Lib/subprocess.py
Misc/NEWS.d/next/Library/2022-01-16-14-07-14.bpo-40280.LtFHfF.rst

index 358f49a5f8cd8b9b3a4f6df43a9a39b40b6a7048..ad08339b25ddc37a7073a54366bfff8c7b239078 100644 (file)
@@ -65,10 +65,15 @@ __all__ = ["Popen", "PIPE", "STDOUT", "call", "check_call", "getstatusoutput",
            # 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,
index b7bd7abd80c4293178b8af2231a569aa407aba23..f5d76760678f6adbf8667a5da3deabbbea31b8b3 100644 (file)
@@ -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).