Skip to content

Commit 7819295

Browse files
committed
make kernel shutdown in unit tests aggressive
1 parent 02c523c commit 7819295

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

jupyter_server/pytest_plugin.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,20 @@ def jp_cleanup_subprocesses(jp_serverapp):
476476
async def _():
477477
terminal_cleanup = jp_serverapp.web_app.settings["terminal_manager"].terminate_all
478478
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+
479493
if asyncio.iscoroutinefunction(terminal_cleanup):
480494
try:
481495
await terminal_cleanup()
@@ -487,10 +501,7 @@ async def _():
487501
except Exception as e:
488502
print(e)
489503
if asyncio.iscoroutinefunction(kernel_cleanup):
490-
try:
491-
await kernel_cleanup()
492-
except Exception as e:
493-
print(e)
504+
await kernel_cleanup_steps()
494505
else:
495506
try:
496507
kernel_cleanup()

0 commit comments

Comments
 (0)