Skip to content

Commit

Permalink
fix: exit solara after last kernel closed more reliably
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Jan 7, 2025
1 parent 4c5a7b9 commit 43a9a29
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions jdaviz/solara.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from pathlib import Path
import signal
import threading

import solara
import solara.lab
Expand All @@ -20,15 +20,19 @@

@solara.lab.on_kernel_start
def on_kernel_start():
print("Starting kernel", solara.get_kernel_id())
# at import time, solara runs with a dummy kernel
# we simply ignore that
if "dummy" in solara.get_kernel_id():
return

def on_kernel_close():
# for some reason, sys.exit(0) does not work here
# see https://github.com/encode/uvicorn/discussions/1103
signal.raise_signal(signal.SIGINT)
def exit_process():
# sys.exit(0) does not work, it just throws an exception
# this really makes the process exit
os._exit(0)
# give the kernel some time to close
threading.Thread(target=exit_process).start()
return on_kernel_close


Expand Down

0 comments on commit 43a9a29

Please sign in to comment.