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