[IPython-dev] Execution semantics and how to set them
takowl at gmail.com
Sun Jan 25 13:57:01 EST 2015
On 25 January 2015 at 10:26, Zakariyya Mughal <zaki.mughal at gmail.com> wrote:
> I'm a language kernel author and I'm looking at the execution semantics
> document[^1] where I see a reference to the "single" execution mode.
> It says that the code
> for i in range(10):
> running in "single" mode would display 10 lines.
> I looked through the IPython source and I see that the execution
> semantics are set as an argument for `run_ast_nodes`[^2], but I see no
> way that the given for-loop would give multiple outputs unless the
> `interactivity` parameter is set to `last` or `all`.
First, let me emphasise that all of this is only relevant for executing
Python code. If you're building a kernel for another language, you should
ignore all of this. That documentation page is only about IPython's own
The three modes described on that page (exec, eval, single) are compilation
modes of Python itself, passed as arguments to the built-in compile()
The parameter passed to our run_ast_nodes() method (which can be all, none,
last or last_expr) controls which of a list of AST nodes are compiled in
'single' mode. Our default of last_expr is chosen specifically so that the
for loop example above does not produce output, because we think that's
more likely to be annoying than useful. There is no way to control this
from the frontend, and I don't think we have any intention to add such a
For your own kernel, you should implement whatever display of output makes
sense given the language and the likely users. For Python, we decided that
it makes sense to automatically display the result of the last statement if
that statement is an expression, and implemented that using the details
described above. For R, I implemented similar behaviour based on the
evaluate package by creating an output_handler with a value= parameter.
Which language are you working on a kernel for?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-dev