On Monday, November 6, 2017 at 4:44:01 AM UTC-6, Edward K. Ream wrote:

*Oops*.  "4" appears in Out[1] *before* the call to handle_execute_reply.  
> In any case, the reply message does not contain "4" anywhere.  Clearly, 
> more investigation is required.
>

Mystery solved.  Results are published on the io_pub channel.  New traces 
show that ZMQTerminalInteractiveShell.handle_iopub contains a switch on the 
message type:

In [1]: 777
execute (KernelClient) code: 777
execute ===== msg sent
handle_iopub (ZMQTerminalInteractiveShell) 
a3e1745c-5f58-4b30-844c-b527e2e381b1
handle_iopub msg_type status
handle_iopub msg_type status
handle_iopub msg_type status
handle_iopub msg_type status
handle_iopub msg_type status
handle_iopub msg_type status
handle_iopub msg_type status
handle_iopub msg_type status
handle_iopub msg_type status
handle_iopub msg_type status
handle_iopub msg_type status
handle_iopub msg_type execute_input
handle_iopub msg_type execute_result
Out[1]: 777
handle_iopub Done
handle_iopub msg_type status
handle_execute_reply (ZMQTerminalInteractiveShell)
handle_iopub (ZMQTerminalInteractiveShell) 
a3e1745c-5f58-4b30-844c-b527e2e381b1

Here is the relevant code:

def handle_iopub(self, msg_id=''):
    """Process messages on the IOPub channel

       This method consumes and processes messages on the IOPub channel,
       such as stdout, stderr, execute_result and status.

       It only displays output that is caused by this session.
    """
    g.trace('(ZMQTerminalInteractiveShell)', msg_id)
    while self.client.iopub_channel.msg_ready():
        sub_msg = self.client.iopub_channel.get_msg()
        msg_type = sub_msg['header']['msg_type']
        g.trace('msg_type', msg_type)
        parent = sub_msg["parent_header"]

        if self.include_output(sub_msg):
            if msg_type == 'status':
                self._execution_state = 
sub_msg["content"]["execution_state"]
            ...
            elif msg_type == 'execute_result':
                if self._pending_clearoutput:
                    print("\r", file=io.stdout, end="")
                    self._pending_clearoutput = False
                self.execution_count = 
int(sub_msg["content"]["execution_count"])
                if not self.from_here(sub_msg):
                    sys.stdout.write(self.other_output_prefix)
                format_dict = sub_msg["content"]["data"]
                self.handle_rich_data(format_dict)

                # taken from DisplayHook.__call__:
                hook = self.displayhook
                hook.start_displayhook()
                hook.write_output_prompt()
                    # EKR: Writes Out[...]
                hook.write_format_data(format_dict)
                hook.log_output(format_dict)
                hook.finish_displayhook()
                g.trace('Done')

As you can see, there are complications.

In general, we want to init everything so that we can use the code above 
unchanged.  We shall see how easy it will be to have the init code "do all 
the work".

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to