Skip to content

Commit

Permalink
Use class-attribute to track shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakobhenningjensen committed Nov 14, 2024
1 parent 95cc5c4 commit 08891e2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion uvicorn/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def __init__(self) -> None:
self.tasks: set[asyncio.Task[None]] = set()
self.default_headers: list[tuple[bytes, bytes]] = []

class ShutdownTrigger:
is_shutdown_triggered: bool = False

class Server:
def __init__(self, config: Config) -> None:
Expand Down Expand Up @@ -261,7 +263,7 @@ async def on_tick(self, counter: int) -> bool:
async def shutdown(self, sockets: list[socket.socket] | None = None) -> None:
if self.config.shutdown_delay:
logger.info(f"Shutting down in {self.config.shutdown_delay} seconds")
self.config.app.uvicorn_shutdown_triggered = True
ShutdownTrigger.is_shutdown_triggered = True
await asyncio.sleep(self.config.shutdown_delay)

logger.info("Shutting down")
Expand Down

0 comments on commit 08891e2

Please sign in to comment.