JupyterLabSession#

class rubin.nublado.client.JupyterLabSession(*, username, session_id, socket, logger)#

Bases: object

Open WebSocket session to a JupyterLab.

Objects of this type should be created via the JupyterLabSessionManager context manager.

Parameters:
  • username (str) – User the session is for.

  • session_id (str) – Session ID of the JupyterLab session.

  • socket (ClientConnection) – Open WebSocket connection.

  • logger (BoundLogger) – Logger to use.

Methods Summary

run_python(code[, context, timeout])

Run a block of Python code in a Jupyter lab kernel.

Methods Documentation

async run_python(code, context=None, *, timeout=None)#

Run a block of Python code in a Jupyter lab kernel.

Parameters:
  • code (str) – Code to run.

  • context (Optional[CodeContext], default: None) – Code context for error reporting.

  • timeout (Optional[timedelta], default: None) – Timeout to enforce on gathering the results of the execution. This only applies to waiting for results, not to sending the message to start code execution (which is governed by the lower-level WebSocket protocol timeouts).

Returns:

Output from the kernel.

Return type:

str

Raises:
  • NubladoExecutionError – Raised if an error was reported by the Jupyter lab kernel.

  • NubladoExecutionTimeoutError – Raised if the code execution timed out. After this happens, it is not safe to continue to use the session and it should be closed.

  • NubladoWebSocketError – Raised if there was a WebSocket protocol error while running code or waiting for the response.

Notes

The output returned is only what the cell prints (its standard output). When run inside Jupyter, the cell will display the result of the last Python code line run. This parser ignores that information (the execute_result message).

display_data is also ignored. This is the message type sent for other types of output, such as when you ask Bokeh to show a figure. It’s a bunch of Javascript that will be interpreted by your browser.

See the JupyterLab wire protocol for the full protocol. What we use is half a layer above that. We care what some messages on the various channels are, but not about the low-level implementation details of how those channels are established over ZMQ, for instance.