From 447d6d3ed178d1c07bf8fa5de55ef4c1227a3799 Mon Sep 17 00:00:00 2001 From: Wouter Tichelaar <9594229+DifferentialityDevelopment@users.noreply.github.com> Date: Thu, 10 Apr 2025 02:17:38 +0200 Subject: [PATCH 1/2] Update rp_fastapi.py Fix for the bug WARNING: You must pass the application as an import string to enable 'reload' or 'workers'. --- runpod/serverless/modules/rp_fastapi.py | 30 ++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/runpod/serverless/modules/rp_fastapi.py b/runpod/serverless/modules/rp_fastapi.py index 1747337d..dda48ce5 100644 --- a/runpod/serverless/modules/rp_fastapi.py +++ b/runpod/serverless/modules/rp_fastapi.py @@ -271,14 +271,28 @@ def start_uvicorn(self, api_host="localhost", api_port=8000, api_concurrency=1): """ Starts the Uvicorn server. """ - uvicorn.run( - self.rp_app, - host=api_host, - port=int(api_port), - workers=int(api_concurrency), - log_level=os.environ.get("UVICORN_LOG_LEVEL", "info"), - access_log=False, - ) + if api_concurrency > 1: + # For multiple workers, we need to use the module:app format + import uvicorn.workers + uvicorn.run( + "runpod.serverless.modules.rp_fastapi:app", + host=api_host, + port=int(api_port), + workers=int(api_concurrency), + log_level=os.environ.get("UVICORN_LOG_LEVEL", "info"), + access_log=False, + factory=True + ) + else: + # For single worker, we can use the app instance directly + uvicorn.run( + self.rp_app, + host=api_host, + port=int(api_port), + workers=1, + log_level=os.environ.get("UVICORN_LOG_LEVEL", "info"), + access_log=False + ) # ----------------------------- Realtime Endpoint ---------------------------- # async def _realtime(self, job: Job): From 5503416dcce7a1b4e15cc022074bee6eebe2cdef Mon Sep 17 00:00:00 2001 From: Wouter Tichelaar <9594229+DifferentialityDevelopment@users.noreply.github.com> Date: Thu, 10 Apr 2025 02:49:18 +0200 Subject: [PATCH 2/2] Update rp_fastapi.py --- runpod/serverless/modules/rp_fastapi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/runpod/serverless/modules/rp_fastapi.py b/runpod/serverless/modules/rp_fastapi.py index dda48ce5..62ccab79 100644 --- a/runpod/serverless/modules/rp_fastapi.py +++ b/runpod/serverless/modules/rp_fastapi.py @@ -285,6 +285,7 @@ def start_uvicorn(self, api_host="localhost", api_port=8000, api_concurrency=1): ) else: # For single worker, we can use the app instance directly + import uvicorn.workers uvicorn.run( self.rp_app, host=api_host,