Skip to content

Commit

Permalink
[3.10] pythongh-112736: Refactor del-safe symbol handling in subproce…
Browse files Browse the repository at this point in the history
…ss (python#112738)

Refactor delete-safe symbol handling in subprocess.

Only module globals are force-cleared during interpreter finalization, using a class reference instead of individually listing the constants everywhere is simpler.
  • Loading branch information
freakboy3742 committed Dec 13, 2024
1 parent 8907786 commit bba3828
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
24 changes: 19 additions & 5 deletions Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@
# NOTE: We intentionally exclude list2cmdline as it is
# considered an internal implementation detail. issue10838.

# use presence of msvcrt to detect Windows-like platforms (see bpo-8110)
try:
import msvcrt
import _winapi
_mswindows = True
except ModuleNotFoundError:
_mswindows = False
import _posixsubprocess
import select
import selectors
else:
_mswindows = True

# some platforms do not support subprocesses
_can_fork_exec = sys.platform not in {"ios", "tvos", "watchos"}

if _mswindows:
import _winapi
from _winapi import (CREATE_NEW_CONSOLE, CREATE_NEW_PROCESS_GROUP,
STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
STD_ERROR_HANDLE, SW_HIDE,
Expand All @@ -95,6 +98,12 @@
"NORMAL_PRIORITY_CLASS", "REALTIME_PRIORITY_CLASS",
"CREATE_NO_WINDOW", "DETACHED_PROCESS",
"CREATE_DEFAULT_ERROR_MODE", "CREATE_BREAKAWAY_FROM_JOB"])
else:
if _can_fork_exec:
import _posixsubprocess

import select
import selectors


# Exception classes used by this module.
Expand Down Expand Up @@ -764,6 +773,11 @@ def __init__(self, args, bufsize=-1, executable=None,
pass_fds=(), *, user=None, group=None, extra_groups=None,
encoding=None, errors=None, text=None, umask=-1, pipesize=-1):
"""Create new Popen instance."""
if not _can_fork_exec:
raise OSError(
errno.ENOTSUP, f"{sys.platform} does not support processes."
)

_cleanup()
# Held while anything is calling waitpid before returncode has been
# updated to prevent clobbering returncode if wait() or poll() are
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The use of del-safe symbols in ``subprocess`` was refactored to allow for use in cross-platform build environments.

0 comments on commit bba3828

Please sign in to comment.