Move client session init to async function.

This commit is contained in:
Robin Huang 2024-08-06 20:38:39 -07:00
parent 6976ccc5ca
commit 8af203ecc6
2 changed files with 6 additions and 2 deletions

View File

@ -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")

View File

@ -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)