<div dir="ltr"><div class="gmail_extra">Hi Andrea,<br><br></div><div class="gmail_extra"><div class="gmail_quote">On 27 February 2014 16:25, Andrea Zonca <span dir="ltr"><<a href="mailto:zonca@sdsc.edu" target="_blank">zonca@sdsc.edu</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id=":1gg" class="" style="overflow:hidden">I am trying to develop a py.test plugin to execute notebook cells as<br>


unit tests [1].<br>
<br>
I send a cell content via `execute` to the kernel, and instead of<br>
getting back a single message,<br>
I get several, so I resorted to just loop through all of them and get<br>
the last, and it works:<br>
<a href="https://github.com/zonca/pytest-ipynb/blob/master/conftest.py#L96" target="_blank">https://github.com/zonca/pytest-ipynb/blob/master/conftest.py#L96</a><br></div></blockquote><div><br></div><div>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.<br>

</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id=":1gg" class="" style="overflow:hidden">

Now, what is the correct way of identifying what is the reply to the<br>
last command<br>
executed?</div></blockquote></div><br></div><div class="gmail_extra">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.<br>

<br></div><div class="gmail_extra">You might want to look at the messaging spec here, especially the 'General Message Format' section:<br><a href="http://ipython.org/ipython-doc/dev/development/messaging.html">http://ipython.org/ipython-doc/dev/development/messaging.html</a><br>

<br>Thanks,<br>Thomas<br></div></div>