|
43 | 43 | import builtins
|
44 | 44 | import errno
|
45 | 45 | import io
|
46 |
| -import locale |
47 | 46 | import os
|
48 | 47 | import time
|
49 |
| -import signal |
50 | 48 | import sys
|
51 | 49 | import threading
|
52 | 50 | import warnings
|
@@ -144,6 +142,8 @@ def __init__(self, returncode, cmd, output=None, stderr=None):
|
144 | 142 |
|
145 | 143 | def __str__(self):
|
146 | 144 | if self.returncode and self.returncode < 0:
|
| 145 | + # Lazy import to improve module import time |
| 146 | + import signal |
147 | 147 | try:
|
148 | 148 | return "Command '%s' died with %r." % (
|
149 | 149 | self.cmd, signal.Signals(-self.returncode))
|
@@ -381,6 +381,8 @@ def _text_encoding():
|
381 | 381 | if sys.flags.utf8_mode:
|
382 | 382 | return "utf-8"
|
383 | 383 | else:
|
| 384 | + # Lazy import to improve module import time |
| 385 | + import locale |
384 | 386 | return locale.getencoding()
|
385 | 387 |
|
386 | 388 |
|
@@ -1665,6 +1667,9 @@ def send_signal(self, sig):
|
1665 | 1667 | # Don't signal a process that we know has already died.
|
1666 | 1668 | if self.returncode is not None:
|
1667 | 1669 | return
|
| 1670 | + |
| 1671 | + # Lazy import to improve module import time |
| 1672 | + import signal |
1668 | 1673 | if sig == signal.SIGTERM:
|
1669 | 1674 | self.terminate()
|
1670 | 1675 | elif sig == signal.CTRL_C_EVENT:
|
@@ -1766,6 +1771,9 @@ def _posix_spawn(self, args, executable, env, restore_signals, close_fds,
|
1766 | 1771 | """Execute program using os.posix_spawn()."""
|
1767 | 1772 | kwargs = {}
|
1768 | 1773 | if restore_signals:
|
| 1774 | + # Lazy import to improve module import time |
| 1775 | + import signal |
| 1776 | + |
1769 | 1777 | # See _Py_RestoreSignals() in Python/pylifecycle.c
|
1770 | 1778 | sigset = []
|
1771 | 1779 | for signame in ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ'):
|
@@ -2215,9 +2223,13 @@ def send_signal(self, sig):
|
2215 | 2223 | def terminate(self):
|
2216 | 2224 | """Terminate the process with SIGTERM
|
2217 | 2225 | """
|
| 2226 | + # Lazy import to improve module import time |
| 2227 | + import signal |
2218 | 2228 | self.send_signal(signal.SIGTERM)
|
2219 | 2229 |
|
2220 | 2230 | def kill(self):
|
2221 | 2231 | """Kill the process with SIGKILL
|
2222 | 2232 | """
|
| 2233 | + # Lazy import to improve module import time |
| 2234 | + import signal |
2223 | 2235 | self.send_signal(signal.SIGKILL)
|
0 commit comments