[IPython-dev] How to identify the execution_reply message

Thomas Kluyver takowl@gmail....
Thu Feb 27 19:13:47 CST 2014


Hi Andrea,

On 27 February 2014 16:25, Andrea Zonca <zonca@sdsc.edu> wrote:

> I am trying to develop a py.test plugin to execute notebook cells as
> unit tests [1].
>
> I send a cell content via `execute` to the kernel, and instead of
> getting back a single message,
> I get several, so I resorted to just loop through all of them and get
> the last, and it works:
> https://github.com/zonca/pytest-ipynb/blob/master/conftest.py#L96
>

Yes, this is intentional. It's not just request/reply: when you ask the
kernel to execute code, there will be at least kernel busy and idle status
messages when it starts and finishes, and there may also be various kinds
of outputs and errors from the code being executed. Finally, the
execute_reply message should be one per execution, and it tells you whether
it finished ok, errored, or was interrupted. It's probably better to do
this by checking the msg_type in the message header, rather than waiting
for the last in a cluster.


> Now, what is the correct way of identifying what is the reply to the
> last command
> executed?
>

I'm not quite sure what you mean, but each returning message should have a
parent_header dict, which contains the headers of the execute_request. So
you should be able to match up the messages coming in with the message you
sent using the msg_id.

You might want to look at the messaging spec here, especially the 'General
Message Format' section:
http://ipython.org/ipython-doc/dev/development/messaging.html

Thanks,
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-dev/attachments/20140227/69f1ece3/attachment.html 


More information about the IPython-dev mailing list