From 8a9b12b1d000c97adb46ed20c2bebc32000b6d59 Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Tue, 9 Apr 2024 17:05:43 +0200 Subject: [PATCH 1/2] feat: stop jdaviz/voila when the browser window closes --- jdaviz/cli.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/jdaviz/cli.py b/jdaviz/cli.py index 6f39eba77a..fb7a9a6c2d 100644 --- a/jdaviz/cli.py +++ b/jdaviz/cli.py @@ -109,7 +109,26 @@ def main(filepaths=None, layout='default', instrument=None, browser='default', VoilaConfiguration.theme = theme if browser != 'default': Voila.browser = browser - sys.exit(Voila().launch_instance(argv=[])) + + voila = Voila.instance() + # monkey patch listen, so we can get a handle on the kernel_manager + # after it is created + previous_listen = voila.listen + + def listen(*args, **kwargs): + # monkey patch remove_kernel, so we can stop the event loop + # when a kernel is removed (which means the browser page was closed) + previous_remove_kernel = voila.kernel_manager.remove_kernel + + def remove_kernel(kernel_id): + previous_remove_kernel(kernel_id) + voila.ioloop.stop() + + voila.kernel_manager.remove_kernel = remove_kernel + return previous_listen(*args, **kwargs) + + voila.listen = listen + sys.exit(voila.launch_instance(argv=[])) finally: os.chdir(start_dir) From 920b616423d726cdeeefddbdd022f16d2df6ba37 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Thu, 11 Apr 2024 15:58:36 -0400 Subject: [PATCH 2/2] changelog entry --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 60fc7cfd31..9dc8b6ce84 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -66,6 +66,8 @@ Bug Fixes - Fix dropdown selection for table format in export plugin. [#2793] +- Standalone mode: stop jdaviz/voila processes when closing app. [#2791] + Cubeviz ^^^^^^^