{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "development:execution",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When IPython kernel receives "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "execute_request"
                }
              ],
              "url": "https://jupyter-client.readthedocs.io/en/latest/messaging.html#execute",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with user code, it processes the message in the following phases:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": true,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Fire the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "pre_execute"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " event."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Fire the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "pre_run_cell"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " event unless silent is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "True"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Execute "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "run_cell"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " method to preprocess "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "code"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", compile and run it, see below for details."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If execution succeeds, expressions in "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "user_expressions"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are computed.    This ensures that any error in the expressions don't affect the main code execution."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Fire the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "post_execute"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " event."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Fire the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "post_run_cell"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " event unless silent is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "True"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "seealso",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "seealso "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "/config/callbacks",
                  "reference": {
                    "__type": "LocalRef",
                    "__tag": 4022,
                    "kind": "docs",
                    "path": "/config/callbacks"
                  },
                  "kind": "docs"
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Execution of cells in the IPython kernel"
        }
      ],
      "level": 0,
      "target": "execution_semantics"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "First, the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "code"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " cell is transformed to expand "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "%magic"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "!system"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " commands by "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "IPython.core.inputtransformer2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Then expanded cell is compiled using standard Python "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "compile",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " function and executed."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Python "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "compile",
              "domain": null,
              "role": "func",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " function provides "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "mode"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " argument to select one of three ways of compiling code:"
            }
          ]
        },
        {
          "__type": "DefList",
          "__tag": 4033,
          "children": [
            {
              "__type": "DefListItem",
              "__tag": 4037,
              "dt": {
                "__type": "Paragraph",
                "__tag": 4045,
                "children": [
                  {
                    "__type": "Emphasis",
                    "__tag": 4047,
                    "children": [
                      {
                        "__type": "Text",
                        "__tag": 4046,
                        "value": "single"
                      }
                    ]
                  }
                ]
              },
              "dd": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Valid for a single interactive statement (though the source can contain   multiple lines, such as a for loop).  When compiled in this mode, the   generated bytecode contains special instructions that trigger the calling of   "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "sys.displayhook",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "sys",
                        "version": "*",
                        "kind": "api",
                        "path": "sys:displayhook"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " for any expression in the block that returns a value.   This means that a single statement can actually produce multiple calls to   "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "sys.displayhook",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "sys",
                        "version": "*",
                        "kind": "api",
                        "path": "sys:displayhook"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", if for example it contains a loop where each   iteration computes an unassigned expression would generate 10 calls        "
                    }
                  ]
                },
                {
                  "__type": "Code",
                  "__tag": 4050,
                  "value": "for i in range(10):\n    i**2",
                  "execution_status": null
                }
              ]
            },
            {
              "__type": "DefListItem",
              "__tag": 4037,
              "dt": {
                "__type": "Paragraph",
                "__tag": 4045,
                "children": [
                  {
                    "__type": "Emphasis",
                    "__tag": 4047,
                    "children": [
                      {
                        "__type": "Text",
                        "__tag": 4046,
                        "value": "exec"
                      }
                    ]
                  }
                ]
              },
              "dd": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An arbitrary amount of source code, this is how modules are compiled.   "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "sys.displayhook",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "sys",
                        "version": "*",
                        "kind": "api",
                        "path": "sys:displayhook"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "never"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " implicitly called."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DefListItem",
              "__tag": 4037,
              "dt": {
                "__type": "Paragraph",
                "__tag": 4045,
                "children": [
                  {
                    "__type": "Emphasis",
                    "__tag": 4047,
                    "children": [
                      {
                        "__type": "Text",
                        "__tag": 4046,
                        "value": "eval"
                      }
                    ]
                  }
                ]
              },
              "dd": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A single expression that returns a value.  "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "sys.displayhook",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "sys",
                        "version": "*",
                        "kind": "api",
                        "path": "sys:displayhook"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "never"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "   implicitly called."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "code"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " field is split into individual blocks each of which is valid for execution in 'single' mode, and then:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If there is only a single block: it is executed in 'single' mode."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If there is more than one block:"
                    }
                  ]
                },
                {
                  "__type": "BulletList",
                  "__tag": 4053,
                  "ordered": false,
                  "start": 1,
                  "children": [
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "if the last block is a single line long, run all but the last in 'exec' mode     and the very last one in 'single' mode.  This makes it easy to type simple     expressions at the end to see computed values."
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "if the last block is no more than two lines long, run all but the last in     'exec' mode and the very last one in 'single' mode.  This makes it easy to     type simple expressions at the end to see computed values.  - otherwise     (last one is also multiline), run all in 'exec' mode"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "otherwise (last block is also multiline), run all in 'exec' mode as a single     unit."
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Running user "
        },
        {
          "__type": "InlineCode",
          "__tag": 4051,
          "value": "code"
        }
      ],
      "level": 0,
      "target": null
    }
  ],
  "local_refs": []
}