From ac634d96e40706882ee61a1c8e01360734124b01 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sun, 16 Jan 2022 14:05:23 +0100 Subject: [PATCH 1/2] bpo-40280: Change subprocess imports for cleaner error on wasm32-emscripten --- Lib/subprocess.py | 15 +++++++-------- .../2022-01-16-14-07-14.bpo-40280.LtFHfF.rst | 4 ++++ 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-01-16-14-07-14.bpo-40280.LtFHfF.rst diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 33f022f8fced66..358f49a5f8cd8b 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -65,16 +65,11 @@ # NOTE: We intentionally exclude list2cmdline as it is # considered an internal implementation detail. issue10838. -try: +_mswindows = sys.platform == "win32" + +if _mswindows: import msvcrt import _winapi - _mswindows = True -except ModuleNotFoundError: - _mswindows = False - import _posixsubprocess - import select - import selectors -else: from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP, STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE, SW_HIDE, @@ -95,6 +90,10 @@ "NORMAL_PRIORITY_CLASS", "REALTIME_PRIORITY_CLASS", "CREATE_NO_WINDOW", "DETACHED_PROCESS", "CREATE_DEFAULT_ERROR_MODE", "CREATE_BREAKAWAY_FROM_JOB"]) +else: + import _posixsubprocess + import select + import selectors # Exception classes used by this module. 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 new file mode 100644 index 00000000000000..7207215a51be6a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-01-16-14-07-14.bpo-40280.LtFHfF.rst @@ -0,0 +1,4 @@ +:mod:`subprocess` now imports Windows-specific imports on ``sys.platform == +"win32"`` and POSIX-specific imports on all other platforms. This gives a +clean exception when ``_posixsubprocess`` is not available (Emscripten +browser target) and it's slightly faster, too. From a11e6d88e8edac210411be187c754ac4a4a53357 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sun, 16 Jan 2022 16:40:03 +0100 Subject: [PATCH 2/2] Reformat blurb --- .../next/Library/2022-01-16-14-07-14.bpo-40280.LtFHfF.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 7207215a51be6a..b7bd7abd80c429 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 on ``sys.platform == -"win32"`` and POSIX-specific imports on all other platforms. This gives a -clean exception when ``_posixsubprocess`` is not available (Emscripten -browser target) and it's slightly faster, too. +:mod:`subprocess` now imports Windows-specific imports when +``sys.platform == "win32"`` 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.