From c740397e4974ae3befc4e538507fa3993bc2085f Mon Sep 17 00:00:00 2001 From: Marc Udoff Date: Tue, 29 Jan 2019 19:04:14 -0500 Subject: [PATCH] Improve comms.rst example This improves the example by making it more copy/pastable out of the box and demoing how you can send a message at various places. It also fixes a poor usage of shadowed variables --- docs/source/comms.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/comms.rst b/docs/source/comms.rst index 1a0a5a325..16aec45f8 100644 --- a/docs/source/comms.rst +++ b/docs/source/comms.rst @@ -65,7 +65,7 @@ containing Javascript to connect to it. .. code-block:: python - def target_func(comm, msg): + def target_func(comm, open_msg): # comm is the kernel Comm instance # msg is the comm_open message @@ -73,8 +73,9 @@ containing Javascript to connect to it. @comm.on_msg def _recv(msg): # Use msg['content']['data'] for the data in the message + comm.send({'echo': msg['content']['data']}) - # Send data to the frontend + # Send data to the frontend on creation comm.send({'foo': 5}) get_ipython().kernel.comm_manager.register_target('my_comm_target', target_func)