mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-118761: Revert "Improve import time of subprocess
(GH-129427)" (#130201)
* Revert "gh-118761: Improve import time of `subprocess` (GH-129427)" This reverts commit49f24650e4
. Also known asf502c8f6a6
in 3.13 (PR #129447) Also known asf65aa0d1bf
in 3.12 (PR #129448) This caused bugs in the `__del__` finalizer: https://github.com/python/cpython/issues/118761#issuecomment-2661504264 --------- Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
655fc8a0fc
commit
ae30646089
2 changed files with 6 additions and 14 deletions
|
@ -43,8 +43,10 @@ getstatusoutput(...): Runs a command in the shell, waits for it to complete,
|
|||
import builtins
|
||||
import errno
|
||||
import io
|
||||
import locale
|
||||
import os
|
||||
import time
|
||||
import signal
|
||||
import sys
|
||||
import threading
|
||||
import warnings
|
||||
|
@ -142,8 +144,6 @@ class CalledProcessError(SubprocessError):
|
|||
|
||||
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))
|
||||
|
@ -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()
|
||||
|
||||
|
||||
|
@ -1665,9 +1663,6 @@ class Popen:
|
|||
# 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:
|
||||
|
@ -1769,9 +1764,6 @@ class Popen:
|
|||
"""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'):
|
||||
|
@ -2221,13 +2213,9 @@ class Popen:
|
|||
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…
Add table
Add a link
Reference in a new issue