diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py index 72525cea1a56e6..b69ed7e4492e77 100644 --- a/Lib/concurrent/futures/process.py +++ b/Lib/concurrent/futures/process.py @@ -857,7 +857,7 @@ def shutdown(self, wait=True, *, cancel_futures=False): shutdown.__doc__ = _base.Executor.shutdown.__doc__ - def terminate_workers(self, signal=signal.SIGINT): + def terminate_workers(self, signal=signal.SIGTERM): """Attempts to terminate the executor's workers using the given signal. Iterates through all of the current processes and sends the given signal if the process is still alive. @@ -866,19 +866,21 @@ def terminate_workers(self, signal=signal.SIGINT): Args: signal: The signal to send to each worker process. Defaults to - signal.SIGINT. + signal.SIGTERM. """ - if self._processes: - for pid, proc in self._processes.items(): - try: - is_alive = proc.is_alive() - except ValueError: - # The process is already exited/closed out. - is_alive = False + if not self._processes: + return - if is_alive: - try: - os.kill(pid, signal) - except ProcessLookupError: - # The process just ended before our signal - pass + for pid, proc in self._processes.items(): + try: + is_alive = proc.is_alive() + except ValueError: + # The process is already exited/closed out. + is_alive = False + + if is_alive: + try: + os.kill(pid, signal) + except ProcessLookupError: + # The process just ended before our signal + pass