Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-118761: Improve import time ofsubprocess#129427

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gpshead merged 2 commits intopython:mainfromhukkin:subprocess-importtime
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
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
16 changes: 14 additions & 2 deletionsLib/subprocess.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,10 +43,8 @@
import builtins
import errno
import io
import locale
import os
import time
import signal
import sys
import threading
import warnings
Expand DownExpand Up@@ -144,6 +142,8 @@ 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 DownExpand Up@@ -381,6 +381,8 @@ 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 DownExpand Up@@ -1664,6 +1666,9 @@ 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 DownExpand Up@@ -1765,6 +1770,9 @@ 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 DownExpand Up@@ -2214,9 +2222,13 @@ 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)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Improve import time of :mod:`subprocess` by lazy importing ``locale`` and
``signal``. Patch by Taneli Hukkinen.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp