Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 606e496

Browse files
authored
bpo-40280: Use presence of msvcrt module to detect Windows (GH-30930)
1 parent 897ce90 commit 606e496

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Lib/subprocess.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@
6565
# NOTE: We intentionally exclude list2cmdline as it is
6666
# considered an internal implementation detail. issue10838.
6767

68-
_mswindows = sys.platform == "win32"
68+
# use presence of msvcrt to detect Windows-like platforms (see bpo-8110)
69+
try:
70+
import msvcrt
71+
except ModuleNotFoundError:
72+
_mswindows = False
73+
else:
74+
_mswindows = True
6975

7076
if _mswindows:
71-
import msvcrt
7277
import _winapi
7378
from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
7479
STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
:mod:`subprocess` now imports Windows-specific imports when
2-
``sys.platform == "win32"`` and POSIX-specific imports on all other
2+
``msvcrt`` module is available, and POSIX-specific imports on all other
33
platforms. This gives a clean exception when ``_posixsubprocess`` is not
4-
available (e.g. Emscripten browser target) and it's slightly faster, too.
4+
available (e.g. Emscripten browser target).

0 commit comments

Comments
 (0)