Skip to content
This repository was archived by the owner on Mar 13, 2020. It is now read-only.
This repository was archived by the owner on Mar 13, 2020. It is now read-only.

Jupyter notebook messages #2

@rebornix

Description

@rebornix

Jupyter notebook frontends community with the kernel through sockets. The kernel has three dedicated sockets for different purpose

image

  • Shell. Frontends use this socket to send execution requests like Code Execution, Completion, etc and Kernel replies
  • IOPub. Kernel broadcasts everything happening in the kernel, including its own status update.
  • Stdin. When kernel requires input from users (frontend), this socket is used to send out the request and receive inputs.

Examples

let's use three examples to get a better understand of what the communications are like when a code cell is executed

Execute code

a=1

Messages:

Shell <— msg_type:”execute_request”, code: `a=1`
IOPub —> msg_type:”status”, execution_state:"busy”
IOPub —> msg_type:”execute_input”, code: `a=1`, execution_count:1
Shell —> msg_type:”execute_reply”, status:”ok”, execution_count:4
IOPub —> msg_type:”status”, execution_state:”idle”
  • Execute code with asynchronous output*
import time, sys
for i in range(8):
    print(i)
    time.sleep(0.5)

Messages:

Shell <— msg_type:”execute_request”, code: `”import time, sys\nfor i in range(8):\n    print(i)\n    time.sleep(0.5)”`
IOPub —> msg_type:”status”, execution_state:"busy”
IOPub —> msg_type:”execute_input”, code: `”import time, sys\nfor i in range(8):\n    print(i)\n    time.sleep(0.5)”`, execution_count:4
IOPub —> msg_type:”stream”, name: “stdout”, text: “0\n”
IOPub —> msg_type:”stream”, name: “stdout”, text: “1\n”
IOPub —> msg_type:”stream”, name: “stdout”, text: “2\n”
IOPub —> msg_type:”stream”, name: “stdout”, text: “3\n”
IOPub —> msg_type:”stream”, name: “stdout”, text: “4\n”
IOPub —> msg_type:”stream", name: “stdout”, text: “5\n”
IOPub —> msg_type:”stream”, name: “stdout”, text: “6\n”
IOPub —> msg_type:”stream”, name: “stdout”, text: “7\n”
IOPub —> msg_type:”status”, execution_state:”idle”
Shell —> msg_type:”execute_reply”, status:”ok”, execution_count:4
  • Execute code with input request*
Shell <— msg_type:”execute_request”, code: `b = input(‘type:’)\nprint(b)`
IOPub —> msg_type:”status”, execution_state:"busy”
IOPub —> msg_type:”execute_input”, code:`b = input(‘type:’)\nprint(b)`, execution_count:7
STDIN —> msg_type:”input_request”, prompt:”type:”, password: false
STDIN <— msg_type: ‘input_reply’, value: “1”
IOPub —> msg_type:”stream”, name: “stdout”, text: “1\n”
IOPub —> msg_type:”status”, execution_state:”idle”
Shell —> msg_type:”execute_reply”, status:”ok”, execution_count:4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions