Skip to content

Commit c36df8a

Browse files
authored
Added documentation about the publish_xxx methods (#431)
1 parent 1550d7c commit c36df8a

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
strategy:
8686
fail-fast: false
8787
matrix:
88-
os: [ windows-2019, windows-2022 ]
88+
os: [ windows-2022, windows-2025 ]
8989

9090
steps:
9191
- uses: actions/checkout@v4

docs/source/example/src/custom_interpreter.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,22 @@ namespace custom
3535
// the data to publish (mime type data) as second argument and metadata
3636
// as third argument.
3737
// Replace "Hello World !!" by what you want to be displayed under the execution cell
38-
nl::json pub_data;
39-
pub_data["text/plain"] = "Hello World !!";
40-
publish_execution_result(request_context, execution_counter, std::move(pub_data), nl::json::object());
38+
// Note: this method should not be called if config.silent is true
39+
if (!config.silent)
40+
{
41+
nl::json pub_data;
42+
pub_data["text/plain"] = "Hello World !!";
43+
publish_execution_result(request_context, execution_counter, std::move(pub_data), nl::json::object());
44+
}
4145

4246
// You can also use this method for publishing errors to the client, if the code
4347
// failed to execute
4448
// publish_execution_error(error_name, error_value, error_traceback);
45-
publish_execution_error(request_context, "TypeError", "123", {"!@#$", "*(*"});
49+
// Note: this method should not be called if config.silent is true
50+
if (!config.silent)
51+
{
52+
publish_execution_error(request_context, "TypeError", "123", {"!@#$", "*(*"});
53+
}
4654

4755
// Call the callback parameter to send the reply
4856
cb(xeus::create_successful_reply());

docs/source/kernel_implementation.rst

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ course the ``execute_request_impl`` which executes the code whenever the client
5151
.. literalinclude:: ./example/src/custom_interpreter.cpp
5252
:language: cpp
5353
:dedent: 4
54-
:lines: 22-49
54+
:lines: 22-57
5555

5656
The result and arguments of the execution request are described in the execute_request_ documentation.
5757

@@ -236,6 +236,34 @@ Create info reply
236236
237237
Thorough information about the kernel's infos variables can be found in the Jupyter kernel docs_.
238238

239+
Outputs and display
240+
-------------------
241+
242+
The ``xinterpreter`` class provides several methods for sending data to be displayed
243+
to the frontend(s), that you can call from the implementation of your interpreter class:
244+
245+
- ``publish_stream``: this method is used to send data that should be print on the standard
246+
output streams (``stdout`` and ``stderr`` in Python, ``std::cout`` and ``std::cerr`` in C++).
247+
The usual way to have it called when executing user code is to redirect standard streams. This
248+
method should not be called when executing code in silent mode (i.e. when ``execute_request_impl``
249+
is called with a ``config`` argument whose ``silent`` member is ``true``).
250+
- ``publish_execution_input``: this method sends the executed code to all the frontends connected
251+
to the kernel. Like ``publish_stream``, it should not be called when executing code in silent mode.
252+
This method is already called in the ``execute_request`` method of the ``xinterpreter`` class and
253+
there should be no need to call it from your implementation. It is provided for backward compatibility
254+
purpose.
255+
- ``publish_exeuction_result``: this sends the result of the execution to all the frontends connected
256+
to the kernel. It should be called when the execution is successful, and the code was not executed
257+
in silent mode.
258+
- ``publish_execution_error``: this method sends an execution error to all the frontends. It should be
259+
called when the code failed to execute and was not executed in silent mode.
260+
- ``display_data``: this method sends data to be displayed to all the frontends. It should be called
261+
from executing a special function in the user code (``display`` in Python and C++, ``display_data``
262+
in MatLab). This function should be called even if the code is executed in silent mode.
263+
- ``update_diplay_data``: when a ``display_id`` is specified for a display, it can be updated later
264+
with a call to this method. Like ``display_data``, this method should be called even if the code
265+
is executed in silent mode.
266+
239267
Implementing the main entry
240268
---------------------------
241269

0 commit comments

Comments
 (0)