From 07b0cf7d2cd9bedc07092925d9269501050c46c0 Mon Sep 17 00:00:00 2001 From: Daniel Han-Chen Date: Tue, 26 May 2026 00:28:23 +0000 Subject: [PATCH] Replace asyncio.get_event_loop with asyncio.get_running_loop for PR #5754 asyncio.get_event_loop() is deprecated in Python 3.10 and will be removed. Replace with asyncio.get_running_loop() at five call sites that all run inside async def functions where a running loop is guaranteed: two async_generate helpers in diffusion.py and three run_in_executor sites in routes/inference.py (audio synth, diffusion load, streaming chat). Addresses the gemini-code-assist bot review. --- studio/backend/core/inference/diffusion.py | 4 ++-- studio/backend/routes/inference.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/studio/backend/core/inference/diffusion.py b/studio/backend/core/inference/diffusion.py index 9921d0543d..c66a3690e5 100644 --- a/studio/backend/core/inference/diffusion.py +++ b/studio/backend/core/inference/diffusion.py @@ -1988,7 +1988,7 @@ async def async_generate( ) -> "Any": """Run ``generate_image`` in the default executor so route handlers do not block the event loop for the 5-30 s a diffusion step takes.""" - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() return await loop.run_in_executor(None, lambda: backend.generate_image(**kwargs)) @@ -2002,7 +2002,7 @@ async def async_generate_with_metadata( fields reflect the pipeline that actually produced the image, even if an unload races the route between the forward returning and the response being assembled (round 13 P2 #9).""" - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() return await loop.run_in_executor( None, lambda: backend.generate_image_with_metadata(**kwargs), diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py index e95bd9b429..effde958e7 100644 --- a/studio/backend/routes/inference.py +++ b/studio/backend/routes/inference.py @@ -2260,7 +2260,7 @@ async def generate_audio( ) try: - wav_bytes, sample_rate = await asyncio.get_event_loop().run_in_executor( + wav_bytes, sample_rate = await asyncio.get_running_loop().run_in_executor( None, gen ) except Exception as e: @@ -2471,7 +2471,7 @@ async def diffusion_load( # AFTER validation. backend = _get_diffusion_backend() try: - status = await asyncio.get_event_loop().run_in_executor( + status = await asyncio.get_running_loop().run_in_executor( None, lambda: backend.load_model( repo_id = resolved_repo_id, @@ -4265,7 +4265,7 @@ async def openai_chat_completions( # the second request's blocking lock acquisition would # freeze the entire event loop, stalling both streams. _DONE = object() # sentinel for generator exhaustion - loop = asyncio.get_event_loop() + loop = asyncio.get_running_loop() gen = generate() while True: if cancel_event.is_set():