Skip to content

gh-118761: Revert "Improve import time of subprocess (GH-129427)" #130201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Revert "gh-118761: Improve import time of subprocess (GH-129427)"
This reverts commit 49f2465.

This caused bugs in the `__del__` finalizer:
 #118761 (comment)
  • Loading branch information
gpshead committed Feb 16, 2025
commit 030d35759a50e3355a2c04376e38c5a6af9af862
16 changes: 2 additions & 14 deletions Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
import builtins
import errno
import io
import locale
import os
import time
import signal
import sys
import threading
import warnings
Expand Down Expand Up @@ -142,8 +144,6 @@ def __init__(self, returncode, cmd, output=None, stderr=None):

def __str__(self):
if self.returncode and self.returncode < 0:
# Lazy import to improve module import time
import signal
try:
return "Command '%s' died with %r." % (
self.cmd, signal.Signals(-self.returncode))
Expand Down Expand Up @@ -381,8 +381,6 @@ def _text_encoding():
if sys.flags.utf8_mode:
return "utf-8"
else:
# Lazy import to improve module import time
import locale
return locale.getencoding()


Expand Down Expand Up @@ -1665,9 +1663,6 @@ def send_signal(self, sig):
# Don't signal a process that we know has already died.
if self.returncode is not None:
return

# Lazy import to improve module import time
import signal
if sig == signal.SIGTERM:
self.terminate()
elif sig == signal.CTRL_C_EVENT:
Expand Down Expand Up @@ -1769,9 +1764,6 @@ def _posix_spawn(self, args, executable, env, restore_signals, close_fds,
"""Execute program using os.posix_spawn()."""
kwargs = {}
if restore_signals:
# Lazy import to improve module import time
import signal

# See _Py_RestoreSignals() in Python/pylifecycle.c
sigset = []
for signame in ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ'):
Expand Down Expand Up @@ -2221,13 +2213,9 @@ def send_signal(self, sig):
def terminate(self):
"""Terminate the process with SIGTERM
"""
# Lazy import to improve module import time
import signal
self.send_signal(signal.SIGTERM)

def kill(self):
"""Kill the process with SIGKILL
"""
# Lazy import to improve module import time
import signal
self.send_signal(signal.SIGKILL)
Loading