Skip to content

Commit

Permalink
fix: Uvicorn graceful shutdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
DABND19 committed May 13, 2024
1 parent 6d2f617 commit 9f78a73
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions aiomisc/service/uvicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
class UvicornService(Service, abc.ABC):
__async_required__: Tuple[str, ...] = (
"start",
"stop",
"create_application",
)

Expand Down Expand Up @@ -114,8 +115,10 @@ async def start(self) -> Any:
)
if not self.sock:
self.sock = config.bind_socket()
server = Server(config)

self.start_event.set()
self.server = Server(config)
self.serve_task = asyncio.create_task(
self.server.serve(sockets=[self.sock])
)

await server.serve(sockets=[self.sock])
async def stop(self, exception: Optional[Exception] = None) -> None:
await self.serve_task

0 comments on commit 9f78a73

Please sign in to comment.