File tree Expand file tree Collapse file tree 4 files changed +13
-1
lines changed Expand file tree Collapse file tree 4 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,8 @@ Options:
114
114
--timeout-graceful-shutdown INTEGER
115
115
Maximum number of seconds to wait for
116
116
graceful shutdown.
117
+ --delayed-shutdown FLOAT
118
+ Time in seconds to delay shutdown when a shutdown-signal is received
117
119
--ssl-keyfile TEXT SSL key file
118
120
--ssl-certfile TEXT SSL certificate file
119
121
--ssl-keyfile-password TEXT SSL keyfile password
Original file line number Diff line number Diff line change @@ -223,6 +223,7 @@ def __init__(
223
223
headers : list [tuple [str , str ]] | None = None ,
224
224
factory : bool = False ,
225
225
h11_max_incomplete_event_size : int | None = None ,
226
+ shutdown_delay : float = 0 ,
226
227
):
227
228
self .app = app
228
229
self .host = host
@@ -268,6 +269,7 @@ def __init__(
268
269
self .encoded_headers : list [tuple [bytes , bytes ]] = []
269
270
self .factory = factory
270
271
self .h11_max_incomplete_event_size = h11_max_incomplete_event_size
272
+ self .shutdown_delay = shutdown_delay
271
273
272
274
self .loaded = False
273
275
self .configure_logging ()
Original file line number Diff line number Diff line change @@ -408,6 +408,7 @@ def main(
408
408
app_dir : str ,
409
409
h11_max_incomplete_event_size : int | None ,
410
410
factory : bool ,
411
+ shutdown_delay : float = 0 ,
411
412
) -> None :
412
413
run (
413
414
app ,
@@ -457,6 +458,7 @@ def main(
457
458
factory = factory ,
458
459
app_dir = app_dir ,
459
460
h11_max_incomplete_event_size = h11_max_incomplete_event_size ,
461
+ shutdown_delay = shutdown_delay
460
462
)
461
463
462
464
@@ -509,6 +511,7 @@ def run(
509
511
app_dir : str | None = None ,
510
512
factory : bool = False ,
511
513
h11_max_incomplete_event_size : int | None = None ,
514
+ shutdown_delay : float = 0 ,
512
515
) -> None :
513
516
if app_dir is not None :
514
517
sys .path .insert (0 , app_dir )
@@ -560,6 +563,7 @@ def run(
560
563
use_colors = use_colors ,
561
564
factory = factory ,
562
565
h11_max_incomplete_event_size = h11_max_incomplete_event_size ,
566
+ shutdown_delay = shutdown_delay
563
567
)
564
568
server = Server (config = config )
565
569
Original file line number Diff line number Diff line change @@ -259,8 +259,12 @@ async def on_tick(self, counter: int) -> bool:
259
259
return False
260
260
261
261
async def shutdown (self , sockets : list [socket .socket ] | None = None ) -> None :
262
- logger .info ("Shutting down" )
262
+ if self .config .shutdown_delay :
263
+ logger .info (f"Shutting down in { self .config .shutdown_delay } seconds" )
264
+ self .config .app .uvicorn_shutdown_triggered = True
265
+ await asyncio .sleep (self .config .shutdown_delay )
263
266
267
+ logger .info ("Shutting down" )
264
268
# Stop accepting new connections.
265
269
for server in self .servers :
266
270
server .close ()
You can’t perform that action at this time.
0 commit comments