Skip to content

Commit

Permalink
Backport PR #2791: feat: stop jdaviz/voila when the browser window cl…
Browse files Browse the repository at this point in the history
…oses (#2799)

Co-authored-by: Maarten Breddels <[email protected]>
  • Loading branch information
meeseeksmachine and maartenbreddels authored Apr 12, 2024
1 parent 4373488 commit e9ea036
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Bug Fixes

- Fix dropdown selection for table format in export plugin. [#2793]

- Standalone mode: stop jdaviz/voila processes when closing app. [#2791]

Cubeviz
^^^^^^^

Expand Down
21 changes: 20 additions & 1 deletion jdaviz/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e9ea036

Please sign in to comment.