Skip to content

Commit

Permalink
Swap to SIGTERM as the default
Browse files Browse the repository at this point in the history
  • Loading branch information
csm10495 committed Dec 17, 2024
1 parent 61c9b14 commit 3bf5464
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions Lib/concurrent/futures/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

0 comments on commit 3bf5464

Please sign in to comment.