|
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 |
@@ -136,8 +138,6 @@ def __init__(self, returncode, cmd, output=None, stderr=None): |
136 | 138 |
|
137 | 139 | def __str__(self): |
138 | 140 | if self.returncode and self.returncode < 0: |
139 | | - # Lazy import to improve module import time |
140 | | - import signal |
141 | 141 | try: |
142 | 142 | return "Command '%s' died with %r." % ( |
143 | 143 | self.cmd, signal.Signals(-self.returncode)) |
@@ -375,8 +375,6 @@ def _text_encoding(): |
375 | 375 | if sys.flags.utf8_mode: |
376 | 376 | return "utf-8" |
377 | 377 | else: |
378 | | - # Lazy import to improve module import time |
379 | | - import locale |
380 | 378 | return locale.getencoding() |
381 | 379 |
|
382 | 380 |
|
@@ -1657,9 +1655,6 @@ def send_signal(self, sig): |
1657 | 1655 | # Don't signal a process that we know has already died. |
1658 | 1656 | if self.returncode is not None: |
1659 | 1657 | return |
1660 | | - |
1661 | | - # Lazy import to improve module import time |
1662 | | - import signal |
1663 | 1658 | if sig == signal.SIGTERM: |
1664 | 1659 | self.terminate() |
1665 | 1660 | elif sig == signal.CTRL_C_EVENT: |
@@ -1764,9 +1759,6 @@ def _posix_spawn(self, args, executable, env, restore_signals, |
1764 | 1759 |
|
1765 | 1760 | kwargs = {} |
1766 | 1761 | if restore_signals: |
1767 | | - # Lazy import to improve module import time |
1768 | | - import signal |
1769 | | - |
1770 | 1762 | # See _Py_RestoreSignals() in Python/pylifecycle.c |
1771 | 1763 | sigset = [] |
1772 | 1764 | for signame in ('SIGPIPE', 'SIGXFZ', 'SIGXFSZ'): |
@@ -2216,13 +2208,9 @@ def send_signal(self, sig): |
2216 | 2208 | def terminate(self): |
2217 | 2209 | """Terminate the process with SIGTERM |
2218 | 2210 | """ |
2219 | | - # Lazy import to improve module import time |
2220 | | - import signal |
2221 | 2211 | self.send_signal(signal.SIGTERM) |
2222 | 2212 |
|
2223 | 2213 | def kill(self): |
2224 | 2214 | """Kill the process with SIGKILL |
2225 | 2215 | """ |
2226 | | - # Lazy import to improve module import time |
2227 | | - import signal |
2228 | 2216 | self.send_signal(signal.SIGKILL) |
0 commit comments