Skip to content

Commit 030d357

Browse files
committed
Revert "pythongh-118761: Improve import time of subprocess (pythonGH-129427)"
This reverts commit 49f2465. This caused bugs in the `__del__` finalizer: python#118761 (comment)
1 parent 655fc8a commit 030d357

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

Lib/subprocess.py

Lines changed: 2 additions & 14 deletions
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
@@ -142,8 +144,6 @@ def __init__(self, returncode, cmd, output=None, stderr=None):
142144

143145
def __str__(self):
144146
if self.returncode and self.returncode < 0:
145-
# Lazy import to improve module import time
146-
import signal
147147
try:
148148
return "Command '%s' died with %r." % (
149149
self.cmd, signal.Signals(-self.returncode))
@@ -381,8 +381,6 @@ def _text_encoding():
381381
if sys.flags.utf8_mode:
382382
return "utf-8"
383383
else:
384-
# Lazy import to improve module import time
385-
import locale
386384
return locale.getencoding()
387385

388386

@@ -1665,9 +1663,6 @@ def send_signal(self, sig):
16651663
# Don't signal a process that we know has already died.
16661664
if self.returncode is not None:
16671665
return
1668-
1669-
# Lazy import to improve module import time
1670-
import signal
16711666
if sig == signal.SIGTERM:
16721667
self.terminate()
16731668
elif sig == signal.CTRL_C_EVENT:
@@ -1769,9 +1764,6 @@ def _posix_spawn(self, args, executable, env, restore_signals, close_fds,
17691764
"""Execute program using os.posix_spawn()."""
17701765
kwargs = {}
17711766
if restore_signals:
1772-
# Lazy import to improve module import time
1773-
import signal
1774-
17751767
# See _Py_RestoreSignals() in Python/pylifecycle.c
17761768
sigset = []
17771769
for signame in ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ'):
@@ -2221,13 +2213,9 @@ def send_signal(self, sig):
22212213
def terminate(self):
22222214
"""Terminate the process with SIGTERM
22232215
"""
2224-
# Lazy import to improve module import time
2225-
import signal
22262216
self.send_signal(signal.SIGTERM)
22272217

22282218
def kill(self):
22292219
"""Kill the process with SIGKILL
22302220
"""
2231-
# Lazy import to improve module import time
2232-
import signal
22332221
self.send_signal(signal.SIGKILL)

0 commit comments

Comments
 (0)