Skip to content

Commit 8c21ebf

Browse files
authored
Fix: Handle missing worker processes on shutdown (#564)
1 parent 96719c3 commit 8c21ebf

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

taskiq/cli/worker/process_manager.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,23 @@ def prepare_workers(self) -> None:
214214
for worker, event in zip(self.workers, events, strict=True):
215215
_wait_for_worker_startup(worker, event)
216216

217+
def _shutdown_workers(self) -> None:
218+
for worker in self.workers:
219+
if worker.pid:
220+
try:
221+
os.kill(worker.pid, signal.SIGINT)
222+
logger.info(
223+
"Stopped process %s with pid %s",
224+
worker.name,
225+
worker.pid,
226+
)
227+
except ProcessLookupError:
228+
logger.info(
229+
"Process %s (pid %s) already terminated",
230+
worker.name,
231+
worker.pid,
232+
)
233+
217234
def start(self) -> int | None: # noqa: C901
218235
"""
219236
Start managing child processes.
@@ -273,9 +290,7 @@ def start(self) -> int | None: # noqa: C901
273290
reloaded_workers.add(action.worker_num)
274291
elif isinstance(action, ShutdownAction):
275292
logger.debug("Process manager closed, killing workers.")
276-
for worker in self.workers:
277-
if worker.pid:
278-
os.kill(worker.pid, signal.SIGINT)
293+
self._shutdown_workers()
279294
return None
280295

281296
for worker_num, worker in enumerate(self.workers):

0 commit comments

Comments
 (0)