-
-
Notifications
You must be signed in to change notification settings - Fork 324
/
Copy path_asgi.py
42 lines (33 loc) · 1021 Bytes
/
_asgi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import annotations
import asyncio
from typing import Any, Awaitable
from asgiref.typing import ASGIApplication
from uvicorn.config import Config as UvicornConfig
from uvicorn.server import Server as UvicornServer
async def serve_development_asgi(
app: ASGIApplication | Any,
host: str,
port: int,
started: asyncio.Event | None,
) -> None:
"""Run a development server for starlette"""
server = UvicornServer(
UvicornConfig(
app,
host=host,
port=port,
loop="asyncio",
reload=True,
)
)
coros: list[Awaitable[Any]] = [server.serve()]
if started:
coros.append(_check_if_started(server, started))
try:
await asyncio.gather(*coros)
finally:
await asyncio.wait_for(server.shutdown(), timeout=3)
async def _check_if_started(server: UvicornServer, started: asyncio.Event) -> None:
while not server.started:
await asyncio.sleep(0.2)
started.set()