"""認証付き起動HTTPへの依存をなくし、GradioのキューをASGI起動時に準備する。""" from contextlib import asynccontextmanager def configure_queue_lifespan(app): previous = app.router.lifespan_context @asynccontextmanager async def lifespan(server): async with previous(server) as state: if not server.startup_events_triggered: blocks = server.get_blocks() blocks.run_startup_events() await blocks.run_extra_startup_events() server.startup_events_triggered = True yield state app.router.lifespan_context = lifespan