From 8af203ecc6c9310113746493e9c927fc2db3bdfc Mon Sep 17 00:00:00 2001 From: Robin Huang Date: Tue, 6 Aug 2024 20:38:39 -0700 Subject: [PATCH] Move client session init to async function. --- main.py | 1 + server.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 479643b8..32e93b08 100644 --- a/main.py +++ b/main.py @@ -214,6 +214,7 @@ if __name__ == "__main__": loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) server = server.PromptServer(loop) + loop.run_until_complete(server.setup()) q = execution.PromptQueue(server) extra_model_paths_config_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "extra_model_paths.yaml") diff --git a/server.py b/server.py index 8a6e3bf7..5044c116 100644 --- a/server.py +++ b/server.py @@ -76,8 +76,7 @@ class PromptServer(): self.prompt_queue = None self.loop = loop self.messages = asyncio.Queue() - timeout = aiohttp.ClientTimeout(total=None) # no timeout - self.client_session = aiohttp.ClientSession(timeout=timeout) + self.client_session = None self.number = 0 middlewares = [cache_control] @@ -584,6 +583,10 @@ class PromptServer(): return web.Response(status=200) + async def setup(self): + timeout = aiohttp.ClientTimeout(total=None) # no timeout + self.client_session = aiohttp.ClientSession(timeout=timeout) + def add_routes(self): self.user_manager.add_routes(self.routes)