|
65 | 65 | # NOTE: We intentionally exclude list2cmdline as it is
|
66 | 66 | # considered an internal implementation detail. issue10838.
|
67 | 67 |
|
| 68 | +# use presence of msvcrt to detect Windows-like platforms (see bpo-8110) |
68 | 69 | try:
|
69 | 70 | import msvcrt
|
70 |
| - import _winapi |
71 |
| - _mswindows = True |
72 | 71 | except ModuleNotFoundError:
|
73 | 72 | _mswindows = False
|
74 |
| - import _posixsubprocess |
75 |
| - import select |
76 |
| - import selectors |
77 | 73 | else:
|
| 74 | + _mswindows = True |
| 75 | + |
| 76 | +# some platforms do not support subprocesses |
| 77 | +_can_fork_exec = sys.platform not in {"ios", "tvos", "watchos"} |
| 78 | + |
| 79 | +if _mswindows: |
| 80 | + import _winapi |
78 | 81 | from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
|
79 | 82 | STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
|
80 | 83 | STD_ERROR_HANDLE, SW_HIDE,
|
|
95 | 98 | "NORMAL_PRIORITY_CLASS", "REALTIME_PRIORITY_CLASS",
|
96 | 99 | "CREATE_NO_WINDOW", "DETACHED_PROCESS",
|
97 | 100 | "CREATE_DEFAULT_ERROR_MODE", "CREATE_BREAKAWAY_FROM_JOB"])
|
| 101 | +else: |
| 102 | + if _can_fork_exec: |
| 103 | + import _posixsubprocess |
| 104 | + |
| 105 | + import select |
| 106 | + import selectors |
98 | 107 |
|
99 | 108 |
|
100 | 109 | # Exception classes used by this module.
|
@@ -764,6 +773,11 @@ def __init__(self, args, bufsize=-1, executable=None,
|
764 | 773 | pass_fds=(), *, user=None, group=None, extra_groups=None,
|
765 | 774 | encoding=None, errors=None, text=None, umask=-1, pipesize=-1):
|
766 | 775 | """Create new Popen instance."""
|
| 776 | + if not _can_fork_exec: |
| 777 | + raise OSError( |
| 778 | + errno.ENOTSUP, f"{sys.platform} does not support processes." |
| 779 | + ) |
| 780 | + |
767 | 781 | _cleanup()
|
768 | 782 | # Held while anything is calling waitpid before returncode has been
|
769 | 783 | # updated to prevent clobbering returncode if wait() or poll() are
|
|
0 commit comments