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

Skip to content

Commit 7f4b69b

Browse files
authored
bpo-40280: Change subprocess imports for cleaner error on wasm32 (GH-30620)
1 parent 91e33ac commit 7f4b69b

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Lib/subprocess.py

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

68-
try:
68+
_mswindows = sys.platform == "win32"
69+
70+
if _mswindows:
6971
import msvcrt
7072
import _winapi
71-
_mswindows = True
72-
except ModuleNotFoundError:
73-
_mswindows = False
74-
import _posixsubprocess
75-
import select
76-
import selectors
77-
else:
7873
from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
7974
STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
8075
STD_ERROR_HANDLE, SW_HIDE,
@@ -95,6 +90,10 @@
9590
"NORMAL_PRIORITY_CLASS", "REALTIME_PRIORITY_CLASS",
9691
"CREATE_NO_WINDOW", "DETACHED_PROCESS",
9792
"CREATE_DEFAULT_ERROR_MODE", "CREATE_BREAKAWAY_FROM_JOB"])
93+
else:
94+
import _posixsubprocess
95+
import select
96+
import selectors
9897

9998

10099
# Exception classes used by this module.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:mod:`subprocess` now imports Windows-specific imports when
2+
``sys.platform == "win32"`` and POSIX-specific imports on all other
3+
platforms. This gives a clean exception when ``_posixsubprocess`` is not
4+
available (e.g. Emscripten browser target) and it's slightly faster, too.

0 commit comments

Comments
 (0)