From dcf1c2bc8e5892c925d922069aa95ca31238f75d Mon Sep 17 00:00:00 2001 From: ali Date: Mon, 3 Jul 2023 13:40:04 +0200 Subject: [PATCH] Save a reference to created tasks, to avoid tasks disappearing (#17946) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Adrian Wälchli (cherry picked from commit 658e1aba26e38d99060793ea5a22f2f3a55bc6fa) --- src/lightning/app/components/serve/auto_scaler.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lightning/app/components/serve/auto_scaler.py b/src/lightning/app/components/serve/auto_scaler.py index dde7722f5da43d..165a6422e45e4e 100644 --- a/src/lightning/app/components/serve/auto_scaler.py +++ b/src/lightning/app/components/serve/auto_scaler.py @@ -257,7 +257,9 @@ async def consumer(self): if batch and (is_batch_ready or is_batch_timeout): self._server_status[server_url] = False # find server with capacity - asyncio.create_task(self.send_batch(batch, server_url)) + # Saving a reference to the result of this function, protects the task disappearing mid-execution + # https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task + task = asyncio.create_task(self.send_batch(batch, server_url)) # noqa: F841 # resetting the batch array, TODO - not locking the array self._batch = self._batch[len(batch) :] self._last_batch_sent = time.time()