Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add kernel-sidecar #16

Merged
merged 9 commits into from
Jan 15, 2024
Merged

add kernel-sidecar #16

merged 9 commits into from
Jan 15, 2024

Conversation

kafonek
Copy link
Contributor

@kafonek kafonek commented Jan 14, 2024

Leaving this in draft status but putting it up so people can try it out and tell me which direction they want to go for an initial prototype of integrating kernel-sidecar.

  • replaces the Notebook and Cell models with those from kernel-sidecar
  • starts an ipykernel process as a subprocess on cell execution (doesn't clean up if you x out of the tauri app)
  • prints out the ZMQ responses during cell execution, doesn't update the UI right now

image

@kafonek
Copy link
Contributor Author

kafonek commented Jan 14, 2024

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

@kafonek kafonek marked this pull request as draft January 14, 2024 01:11
@rgbkrk
Copy link
Member

rgbkrk commented Jan 14, 2024

It looks like we'll have to change our Cargo toml with custom instructions for windows.

error[E0432]: unresolved imports `tokio::net::UnixListener`, `tokio::net::UnixStream`
  --> C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\zeromq-0.3.4\src\transport\ipc.rs:2:18
   |
2  | use tokio::net::{UnixListener, UnixStream};
   |                  ^^^^^^^^^^^^  ^^^^^^^^^^ no `UnixStream` in `net`
   |                  |
   |                  no `UnixListener` in `net`
   |                  help: a similar name exists in the module: `TcpListener`
   |
note: found an item that was configured out
  --> C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.35.1\src\net\mod.rs:50:29
   |
50 |     pub use unix::listener::UnixListener;
   |                             ^^^^^^^^^^^^
note: found an item that was configured out
  --> C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.35.1\src\net\mod.rs:51:27
   |
51 |     pub use unix::stream::UnixStream;
   |                           ^^^^^^^^^^

Deno probably has the right bits.

@@ -83,65 +108,18 @@ impl AppState {

let mut notebooks = self.notebooks.lock().await;
if let Some(notebook) = notebooks.get_mut(window_id) {
notebook.update_cell(cell_id, new_content);
if let Some(cell) = notebook.get_mut_cell(cell_id) {
cell.set_source(new_content);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

state: State<'_, AppState>,
window: Window,
) -> Result<Option<String>, String> {
async fn create_cell(state: State<'_, AppState>, window: Window) -> Result<Option<String>, String> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a bit to realize this was just a formatting change. I wonder if I'm on a different rust version locally or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, what do you want to do with formatting? I ran cargo +nightly fmt / cargo clippy --fix with a rustfmt.toml that has the line imports_granularity = "Module" (not relevant to the line you have here, just on import formatting).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just let VS Code do its thing with clippy. I wouldn't be surprised if I have some other setting interfering. No biggie for now, I can just follow your process on it when I commit.


async fn start_kernel(&self, window_id: &str) -> (JupyterKernel, Client) {
info!("Starting kernel for window with ID: {}", window_id);
let silent = true; // true = send ipykernel subprocess stdout to /dev/null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to be able to collect the stdout/stderr from the subprocess, mostly for debugging. It's very useful for setups involving background work like Spark.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I see how the process is spawned, we can leave this to future work.

async fn start_kernel(&self, window_id: &str) -> (JupyterKernel, Client) {
info!("Starting kernel for window with ID: {}", window_id);
let silent = true; // true = send ipykernel subprocess stdout to /dev/null
let kernel = JupyterKernel::ipython(silent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on this, is the process launching synchronous?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, using std::process::Command there. Looks like there's a crate for async process, haven't tried it out https://docs.rs/async-process/latest/async_process/struct.Command.html

You think spawning the process should be async? I can create an issue in kernel-sidecar and research it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tauri has a built in for launching an asynchronous process, which I'm guessing wraps around tokio. We can touch this later since it's not a blocker at the moment.

@rgbkrk
Copy link
Member

rgbkrk commented Jan 14, 2024

Future direction I'm curious about for us is if/how we're going to do events. I see how events are done both in the Rust backend and JS frontend in the Tauri docs: https://tauri.app/v1/guides/features/events/. What I'm not sure about is how we're going to receive updates from kernel sidecar and send those events on to the client.

@rgbkrk
Copy link
Member

rgbkrk commented Jan 14, 2024

I'll start hacking on a frontend receiver for cell and output updates in a new branch.

Update: did it here

@rgbkrk rgbkrk force-pushed the mrk/kernel-sidecar-initial branch 2 times, most recently from f7749a7 to 084fdf1 Compare January 15, 2024 01:00
@rgbkrk rgbkrk marked this pull request as ready for review January 15, 2024 15:07
@rgbkrk
Copy link
Member

rgbkrk commented Jan 15, 2024

Looks like zeromq/zmq.rs#185 did the trick. Thanks @mmastrac for the quick ship. 🚀

@rgbkrk rgbkrk merged commit da4ac0b into main Jan 15, 2024
3 checks passed
@rgbkrk rgbkrk deleted the mrk/kernel-sidecar-initial branch January 15, 2024 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants