Commit 7819295 1 parent 02c523c commit 7819295 Copy full SHA for 7819295
File tree 1 file changed +15
-4
lines changed
1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -476,6 +476,20 @@ def jp_cleanup_subprocesses(jp_serverapp):
476
476
async def _ ():
477
477
terminal_cleanup = jp_serverapp .web_app .settings ["terminal_manager" ].terminate_all
478
478
kernel_cleanup = jp_serverapp .kernel_manager .shutdown_all
479
+
480
+ async def kernel_cleanup_steps ():
481
+ # Try a graceful shutdown with a timeout
482
+ try :
483
+ await asyncio .wait_for (kernel_cleanup (), timeout = 15.0 )
484
+ except asyncio .TimeoutError :
485
+ # Now force a shutdown
486
+ try :
487
+ await asyncio .wait_for (kernel_cleanup (now = True ), timeout = 15.0 )
488
+ except asyncio .TimeoutError :
489
+ print (Exception ("Kernel never shutdown!" ))
490
+ except Exception as e :
491
+ print (e )
492
+
479
493
if asyncio .iscoroutinefunction (terminal_cleanup ):
480
494
try :
481
495
await terminal_cleanup ()
@@ -487,10 +501,7 @@ async def _():
487
501
except Exception as e :
488
502
print (e )
489
503
if asyncio .iscoroutinefunction (kernel_cleanup ):
490
- try :
491
- await kernel_cleanup ()
492
- except Exception as e :
493
- print (e )
504
+ await kernel_cleanup_steps ()
494
505
else :
495
506
try :
496
507
kernel_cleanup ()
You can’t perform that action at this time.
0 commit comments