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