Skip to content

Commit

Permalink
🚀 Always launch a new Jupyter Server
Browse files Browse the repository at this point in the history
Fixes #1716
  • Loading branch information
rowanc1 committed Jan 10, 2025
1 parent 67bc9b8 commit 127f083
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-baboons-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-cli": patch
---

Do not findExistingJupyterServer when using execute
9 changes: 6 additions & 3 deletions docs/execute-notebooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ In order to execute your MyST content, you must install a Jupyter Server and the
## Expect a code-cell to fail

By default, MyST will stop executing a notebook if a cell raises an error.
If instead you'd like MyST to continue executing subsequent cells (e.g., in order to demonstrate an expected error message), add the `raises-exception` tag to the cell.
If instead you'd like MyST to continue executing subsequent cells (e.g., in order to demonstrate an expected error message), add the `raises-exception` tag to the cell (see [all cell tags](#tbl:notebook-cell-tags)).
If a cell with this tag raises an error, then the error is provided with the cell output, and MyST will continue executing the rest of the cells in a notebook.

## Adding Tags to Notebook Cells

The easiest way to add cell tags is via [the JupyterLab interface](https://jupyterlab.readthedocs.io).
Additionally, you can specify tags (and other cell metadata) with markdown using the {myst:directive}`code-cell` directive.

Here's an example of adding this tag with a {myst:directive}`code-cell` directive:

````markdown
Expand All @@ -62,6 +63,8 @@ name = input("What is your name?")
```
````

Additional [cell tags](#tbl:notebook-cell-tags) to hide, remove, or raise exceptions are also possible.

## Cache execution outputs

When MyST executes your notebook, it will store the outputs in a cache in a folder called `execute/` in your MyST build folder.
Expand Down Expand Up @@ -98,7 +101,7 @@ Jupyter Server is only responsible for orchestrating execution of your code. To
pip install ipykernel
```

If Jupyter Server is installed and the `--execute` flag is passed to `myst start` or `myst build`, then MyST will attempt to find a healthy existing Jupyter Server. Internally, this is performed using `python -m jupyter_server list`. If no existing servers are found, then MyST will attempt to launch one using `python -m jupyter_server`.
If Jupyter Server is installed and the `--execute` flag is passed to `myst start` or `myst build` MyST will attempt to launch a Jupyter Server using `python -m jupyter_server`.

## Manually launch a Jupyter server

Expand Down
16 changes: 5 additions & 11 deletions packages/myst-cli/src/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { ISession } from './types.js';
import { isWhiteLabelled } from '../utils/whiteLabelling.js';
import { KernelManager, ServerConnection, SessionManager } from '@jupyterlab/services';
import type { JupyterServerSettings } from 'myst-execute';
import { findExistingJupyterServer, launchJupyterServer } from 'myst-execute';
import { launchJupyterServer } from 'myst-execute';
import type { RequestInfo, RequestInit } from 'node-fetch';
import { default as nodeFetch, Headers, Request, Response } from 'node-fetch';

Expand Down Expand Up @@ -229,16 +229,10 @@ export class Session implements ISession {
token: process.env.JUPYTER_TOKEN,
};
} else {
// Load existing running server
const existing = await findExistingJupyterServer(this);
if (existing) {
this.log.debug(`Found existing server on: ${existing.appUrl}`);
partialServerSettings = existing;
} else {
this.log.debug(`Launching jupyter server on ${this.sourcePath()}`);
// Create and load new server
partialServerSettings = await launchJupyterServer(this.sourcePath(), this.log);
}
// Note: To use an existing Jupyter server use `findExistingJupyterServer`, see #1716
this.log.debug(`Launching jupyter server on ${this.sourcePath()}`);
// Create and load new server
partialServerSettings = await launchJupyterServer(this.sourcePath(), this.log);
}

const serverSettings = ServerConnection.makeSettings(partialServerSettings);
Expand Down

0 comments on commit 127f083

Please sign in to comment.