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.
This commit is contained in:
parent
ca68fd5d13
commit
07b0cf7d2c
2 changed files with 5 additions and 5 deletions
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue