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