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

Commitf65aa0d

Browse files
[3.12]gh-118761: Improve import time ofsubprocess (GH-129427) (#129448)
gh-118761: Improve import time of `subprocess` (GH-129427)* subprocess: lazy import signal and locale to improve module import time(cherry picked from commit49f2465)Co-authored-by: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com>
1 parent0e54315 commitf65aa0d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

‎Lib/subprocess.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@
4343
importbuiltins
4444
importerrno
4545
importio
46-
importlocale
4746
importos
4847
importtime
49-
importsignal
5048
importsys
5149
importthreading
5250
importwarnings
@@ -138,6 +136,8 @@ def __init__(self, returncode, cmd, output=None, stderr=None):
138136

139137
def__str__(self):
140138
ifself.returncodeandself.returncode<0:
139+
# Lazy import to improve module import time
140+
importsignal
141141
try:
142142
return"Command '%s' died with %r."% (
143143
self.cmd,signal.Signals(-self.returncode))
@@ -375,6 +375,8 @@ def _text_encoding():
375375
ifsys.flags.utf8_mode:
376376
return"utf-8"
377377
else:
378+
# Lazy import to improve module import time
379+
importlocale
378380
returnlocale.getencoding()
379381

380382

@@ -1655,6 +1657,9 @@ def send_signal(self, sig):
16551657
# Don't signal a process that we know has already died.
16561658
ifself.returncodeisnotNone:
16571659
return
1660+
1661+
# Lazy import to improve module import time
1662+
importsignal
16581663
ifsig==signal.SIGTERM:
16591664
self.terminate()
16601665
elifsig==signal.CTRL_C_EVENT:
@@ -1759,6 +1764,9 @@ def _posix_spawn(self, args, executable, env, restore_signals,
17591764

17601765
kwargs= {}
17611766
ifrestore_signals:
1767+
# Lazy import to improve module import time
1768+
importsignal
1769+
17621770
# See _Py_RestoreSignals() in Python/pylifecycle.c
17631771
sigset= []
17641772
forsignamein ('SIGPIPE','SIGXFZ','SIGXFSZ'):
@@ -2208,9 +2216,13 @@ def send_signal(self, sig):
22082216
defterminate(self):
22092217
"""Terminate the process with SIGTERM
22102218
"""
2219+
# Lazy import to improve module import time
2220+
importsignal
22112221
self.send_signal(signal.SIGTERM)
22122222

22132223
defkill(self):
22142224
"""Kill the process with SIGKILL
22152225
"""
2226+
# Lazy import to improve module import time
2227+
importsignal
22162228
self.send_signal(signal.SIGKILL)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improve import time of:mod:`subprocess` by lazy importing ``locale`` and
2+
``signal``. Patch by Taneli Hukkinen.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp