File size: 655 Bytes
90c32b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""認証付き起動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