Skip to content

Commit 042b492

Browse files
miss-islingtongpsheadpicnixz
authored
[3.12] gh-118761: Revert "Improve import time of subprocess (GH-129427)" (GH-130201) (#130205)
gh-118761: Revert "Improve import time of `subprocess` (GH-129427)" (GH-130201) * Revert "gh-118761: Improve import time of `subprocess` (GH-129427)" This reverts commit 49f2465. Also known as f502c8f in 3.13 (PR GH-129447) Also known as f65aa0d in 3.12 (PR GH-129448) This caused bugs in the `__del__` finalizer: #118761 (comment) --------- (cherry picked from commit ae30646) Co-authored-by: Gregory P. Smith <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 4f09a85 commit 042b492

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

Lib/subprocess.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
import builtins
4444
import errno
4545
import io
46+
import locale
4647
import os
4748
import time
49+
import signal
4850
import sys
4951
import threading
5052
import warnings
@@ -136,8 +138,6 @@ def __init__(self, returncode, cmd, output=None, stderr=None):
136138

137139
def __str__(self):
138140
if self.returncode and self.returncode < 0:
139-
# Lazy import to improve module import time
140-
import signal
141141
try:
142142
return "Command '%s' died with %r." % (
143143
self.cmd, signal.Signals(-self.returncode))
@@ -375,8 +375,6 @@ def _text_encoding():
375375
if sys.flags.utf8_mode:
376376
return "utf-8"
377377
else:
378-
# Lazy import to improve module import time
379-
import locale
380378
return locale.getencoding()
381379

382380

@@ -1657,9 +1655,6 @@ def send_signal(self, sig):
16571655
# Don't signal a process that we know has already died.
16581656
if self.returncode is not None:
16591657
return
1660-
1661-
# Lazy import to improve module import time
1662-
import signal
16631658
if sig == signal.SIGTERM:
16641659
self.terminate()
16651660
elif sig == signal.CTRL_C_EVENT:
@@ -1764,9 +1759,6 @@ def _posix_spawn(self, args, executable, env, restore_signals,
17641759

17651760
kwargs = {}
17661761
if restore_signals:
1767-
# Lazy import to improve module import time
1768-
import signal
1769-
17701762
# See _Py_RestoreSignals() in Python/pylifecycle.c
17711763
sigset = []
17721764
for signame in ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ'):
@@ -2216,13 +2208,9 @@ def send_signal(self, sig):
22162208
def terminate(self):
22172209
"""Terminate the process with SIGTERM
22182210
"""
2219-
# Lazy import to improve module import time
2220-
import signal
22212211
self.send_signal(signal.SIGTERM)
22222212

22232213
def kill(self):
22242214
"""Kill the process with SIGKILL
22252215
"""
2226-
# Lazy import to improve module import time
2227-
import signal
22282216
self.send_signal(signal.SIGKILL)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Reverts a change in the previous release attempting to make some stdlib
2+
imports used within the :mod:`subprocess` module lazy as this was causing
3+
errors during ``__del__`` finalizers calling methods such as ``terminate``, or
4+
``kill``, or ``send_signal``.

0 commit comments

Comments
 (0)