Skip to content

Commit 95da793

Browse files
committed
repl: shutdown all kernels on app quit
1 parent 1c21718 commit 95da793

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

crates/repl/src/repl_store.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::future::Future;
12
use std::sync::Arc;
23

34
use anyhow::{Context as _, Result};
@@ -10,7 +11,8 @@ use project::{Fs, Project, WorktreeId};
1011
use settings::{Settings, SettingsStore};
1112

1213
use crate::kernels::{
13-
list_remote_kernelspecs, local_kernel_specifications, python_env_kernel_specifications,
14+
Kernel, list_remote_kernelspecs, local_kernel_specifications,
15+
python_env_kernel_specifications,
1416
};
1517
use crate::{JupyterSettings, KernelSpecification, Session};
1618

@@ -47,9 +49,12 @@ impl ReplStore {
4749
}
4850

4951
pub fn new(fs: Arc<dyn Fs>, cx: &mut Context<Self>) -> Self {
50-
let subscriptions = vec![cx.observe_global::<SettingsStore>(move |this, cx| {
51-
this.set_enabled(JupyterSettings::enabled(cx), cx);
52-
})];
52+
let subscriptions = vec![
53+
cx.observe_global::<SettingsStore>(move |this, cx| {
54+
this.set_enabled(JupyterSettings::enabled(cx), cx);
55+
}),
56+
cx.on_app_quit(Self::shutdown_all_sessions),
57+
];
5358

5459
let this = Self {
5560
fs,
@@ -281,6 +286,16 @@ impl ReplStore {
281286
self.sessions.remove(&entity_id);
282287
}
283288

289+
fn shutdown_all_sessions(&mut self, cx: &mut Context<Self>) -> impl Future<Output = ()> + use<> {
290+
for session in self.sessions.values() {
291+
session.update(cx, |session, _cx| {
292+
session.kernel = Kernel::Shutdown;
293+
});
294+
}
295+
self.sessions.clear();
296+
futures::future::ready(())
297+
}
298+
284299
#[cfg(test)]
285300
pub fn set_kernel_specs_for_testing(
286301
&mut self,

0 commit comments

Comments
 (0)