From 48211e8ce2703084a8ef9bcb0f4123e986822c44 Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Thu, 18 Jul 2024 19:35:05 -0700 Subject: [PATCH] repl: Check process status and propagate to output (#14782) image Release Notes: - N/A --- crates/repl/src/kernels.rs | 1 - crates/repl/src/outputs.rs | 2 +- crates/repl/src/session.rs | 53 +++++++++++++++++++++++++++++++++++++- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/crates/repl/src/kernels.rs b/crates/repl/src/kernels.rs index c3118961f4c0e91b484f855738edbd37dbcc900f..ad2f70339f964a835b5076225820b02cc0b93b39 100644 --- a/crates/repl/src/kernels.rs +++ b/crates/repl/src/kernels.rs @@ -218,7 +218,6 @@ impl RunningKernel { .with_context(|| format!("Failed to create jupyter runtime dir {runtime_dir:?}"))?; let connection_path = runtime_dir.join(format!("kernel-zed-{entity_id}.json")); let content = serde_json::to_string(&connection_info)?; - // write out file to disk for kernel fs.atomic_write(connection_path.clone(), content).await?; let mut cmd = kernel_specification.command(&connection_path)?; diff --git a/crates/repl/src/outputs.rs b/crates/repl/src/outputs.rs index cc55384e970d4246828c7231e1652664ddd64e74..c7de7c6930ed6db1c03a29e1e772c332faf3c6ec 100644 --- a/crates/repl/src/outputs.rs +++ b/crates/repl/src/outputs.rs @@ -363,7 +363,7 @@ impl LineHeight for OutputType { } } -#[derive(Default, Clone)] +#[derive(Default, Clone, Debug)] pub enum ExecutionStatus { #[default] Unknown, diff --git a/crates/repl/src/session.rs b/crates/repl/src/session.rs index 7deeb1a12cefbb4625c7a93201bc67e566b9a04a..e2f50db76eb86110c6b0324e37b2fbd9fe864194 100644 --- a/crates/repl/src/session.rs +++ b/crates/repl/src/session.rs @@ -177,11 +177,62 @@ impl Session { let kernel = kernel.await; match kernel { - Ok((kernel, mut messages_rx)) => { + Ok((mut kernel, mut messages_rx)) => { this.update(&mut cx, |this, cx| { // At this point we can create a new kind of kernel that has the process and our long running background tasks + + let status = kernel.process.status(); this.kernel = Kernel::RunningKernel(kernel); + cx.spawn(|session, mut cx| async move { + let error_message = match status.await { + Ok(status) => { + if status.success() { + log::info!("kernel process exited successfully"); + return; + } + + format!("kernel process exited with status: {:?}", status) + } + Err(err) => { + format!("kernel process exited with error: {:?}", err) + } + }; + + log::error!("{}", error_message); + + session + .update(&mut cx, |session, cx| { + session.kernel = + Kernel::ErroredLaunch(error_message.clone()); + + session.blocks.values().for_each(|block| { + block.execution_view.update( + cx, + |execution_view, cx| { + match execution_view.status { + ExecutionStatus::Finished => { + // Do nothing when the output was good + } + _ => { + // All other cases, set the status to errored + execution_view.status = + ExecutionStatus::KernelErrored( + error_message.clone(), + ) + } + } + cx.notify(); + }, + ); + }); + + cx.notify(); + }) + .ok(); + }) + .detach(); + this.messaging_task = cx.spawn(|session, mut cx| async move { while let Some(message) = messages_rx.next().await { session