[IPython-dev] How to identify the execution_reply message
Thu Feb 27 19:13:47 CST 2014
On 27 February 2014 16:25, Andrea Zonca <firstname.lastname@example.org> wrote:
> I am trying to develop a py.test plugin to execute notebook cells as
> unit tests .
> 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:
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
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:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-dev