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

Commit49f2465

Browse files
authored
gh-118761: Improve import time ofsubprocess (GH-129427)
* subprocess: lazy import signal and locale to improve module import time
1 parent5ff2fbc commit49f2465

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
@@ -144,6 +142,8 @@ def __init__(self, returncode, cmd, output=None, stderr=None):
144142

145143
def__str__(self):
146144
ifself.returncodeandself.returncode<0:
145+
# Lazy import to improve module import time
146+
importsignal
147147
try:
148148
return"Command '%s' died with %r."% (
149149
self.cmd,signal.Signals(-self.returncode))
@@ -381,6 +381,8 @@ def _text_encoding():
381381
ifsys.flags.utf8_mode:
382382
return"utf-8"
383383
else:
384+
# Lazy import to improve module import time
385+
importlocale
384386
returnlocale.getencoding()
385387

386388

@@ -1664,6 +1666,9 @@ def send_signal(self, sig):
16641666
# Don't signal a process that we know has already died.
16651667
ifself.returncodeisnotNone:
16661668
return
1669+
1670+
# Lazy import to improve module import time
1671+
importsignal
16671672
ifsig==signal.SIGTERM:
16681673
self.terminate()
16691674
elifsig==signal.CTRL_C_EVENT:
@@ -1765,6 +1770,9 @@ def _posix_spawn(self, args, executable, env, restore_signals, close_fds,
17651770
"""Execute program using os.posix_spawn()."""
17661771
kwargs= {}
17671772
ifrestore_signals:
1773+
# Lazy import to improve module import time
1774+
importsignal
1775+
17681776
# See _Py_RestoreSignals() in Python/pylifecycle.c
17691777
sigset= []
17701778
forsignamein ('SIGPIPE','SIGXFZ','SIGXFSZ'):
@@ -2214,9 +2222,13 @@ def send_signal(self, sig):
22142222
defterminate(self):
22152223
"""Terminate the process with SIGTERM
22162224
"""
2225+
# Lazy import to improve module import time
2226+
importsignal
22172227
self.send_signal(signal.SIGTERM)
22182228

22192229
defkill(self):
22202230
"""Kill the process with SIGKILL
22212231
"""
2232+
# Lazy import to improve module import time
2233+
importsignal
22222234
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