Repository: ipython/ipython

Issue:
"AssertionError: Missing message part." in ipython-qtconsole --pure
Running `ipython-qtconsole --pure` and then entering something into the console that raises an error (like `sdfsdf`) causes this:

```
{'content': {'user_variables': [], 'code': 'sdfsdf\n', 'user_expressions': {}, 'silent': False},
 'header': {'username': 'mspacek', 'msg_id': 0, 'session': 'd3ee91be-fedf-44e6-839a-079946789ed9'},
 'msg_type': 'execute_request',
 'parent_header': {}}
{'content': {u'status': u'error', u'ename': u'NameError', u'evalue': u"name 'sdfsdf' is not defined", u'traceback': ['Traceback (most recent call last):\n', '  File "/home/mspacek/source/ipython/IPython/zmq/pykernel.py", line 122, in execute_request\n    exec comp_code in self.user_ns, self.user_ns\n', '  File "<zmq-kernel>", line 1, in <module>\n', "NameError: name 'sdfsdf' is not defined\n"]},
 'header': {'username': u'kernel', 'msg_id': 2, 'session': '808fb1bb-750f-4df9-9787-db19d2f7506a'},
 'msg_type': u'execute_reply',
 'parent_header': {'username': 'mspacek', 'msg_id': 0, 'session': 'd3ee91be-fedf-44e6-839a-079946789ed9'}}
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
/home/mspacek/bzr/neuropy/qt/neuropy/<string> in <module>()

/home/mspacek/source/ipython/IPython/zmq/entry_point.pyc in main()
    156         namespace = make_argument_parser().parse_args()
    157         kernel = make_kernel(namespace, kernel_factory, OutStream, DisplayHook)
--> 158         start_kernel(namespace, kernel)
    159     return main
    160 

/home/mspacek/source/ipython/IPython/zmq/entry_point.pyc in start_kernel(namespace=Namespace(hb=51618, ip='127.0.0.1', no_stderr=Fa...e, parent=True, pub=33482, req=45109, xrep=55285), kernel=<IPython.zmq.pykernel.Kernel object>)
    147 
    148     # Start the kernel mainloop.
--> 149     kernel.start()
    150 
    151 

/home/mspacek/source/ipython/IPython/zmq/pykernel.pyc in start(self=<IPython.zmq.pykernel.Kernel object>)
     79                 print >> sys.__stderr__, "UNKNOWN MESSAGE TYPE:", omsg
     80             else:
---> 81                 handler(ident, omsg)
        global IJd = undefined
        global n = undefined
        global X = undefined
        global S = undefined
        global NR1 = undefined
        global u = undefined
     82 
     83     def record_ports(self, xrep_port, pub_port, req_port, hb_port):

/home/mspacek/source/ipython/IPython/zmq/pykernel.pyc in execute_request(self=<IPython.zmq.pykernel.Kernel object>, ident='d3ee91be-fedf-44e6-839a-079946789ed9', parent={'content': {'user_variables': [], 'code': 'sdfs...arent_header': {}, 'msg_type': 'execute_request'})
    143         print>>sys.__stdout__, Message(reply_msg)
    144         if reply_msg['content']['status'] == u'error':
--> 145             self._abort_queue()
    146 
    147     def complete_request(self, ident, parent):

/home/mspacek/source/ipython/IPython/zmq/pykernel.pyc in _abort_queue(self=<IPython.zmq.pykernel.Kernel object>)
    181                     break
    182             else:
--> 183                 assert ident is not None, "Missing message part."
    184             print>>sys.__stdout__, "Aborting:"
    185             print>>sys.__stdout__, Message(msg)

AssertionError: Missing message part.
```

Shortly thereafter, I get the dialog box informing me that the kernel has been inactive for 3.00 seconds, and do I want to restart...



Discussion:

Resolving patch:
diff --git a/IPython/zmq/pykernel.py b/IPython/zmq/pykernel.py
--- a/IPython/zmq/pykernel.py
+++ b/IPython/zmq/pykernel.py
@@ -174,13 +174,11 @@ def shutdown_request(self, ident, parent):
 
     def _abort_queue(self):
         while True:
-            try:
-                ident,msg = self.session.recv(self.reply_socket, zmq.NOBLOCK)
-            except zmq.ZMQError, e:
-                if e.errno == zmq.EAGAIN:
-                    break
+            ident,msg = self.session.recv(self.reply_socket, zmq.NOBLOCK)
+            if msg is None:
+                break
             else:
-                assert ident is not None, "Missing message part."
+                assert ident is not None, "Unexpected missing message part."
             print>>sys.__stdout__, "Aborting:"
             print>>sys.__stdout__, Message(msg)
             msg_type = msg['msg_type']


Test patch: