From 8d3b96f6d96e066dbb06a217b28ff3f98584e961 2011-12-06 01:40:57 From: Thomas Kluyver Date: 2011-12-06 01:40:57 Subject: [PATCH] Minor tidy up of zmqterminal.completer --- diff --git a/IPython/frontend/zmqterminal/completer.py b/IPython/frontend/zmqterminal/completer.py index e85116b..cd75059 100644 --- a/IPython/frontend/zmqterminal/completer.py +++ b/IPython/frontend/zmqterminal/completer.py @@ -3,6 +3,10 @@ import readline import time import sys stdout = sys.stdout + +class TimeoutError(Exception): + pass + class ClientCompleter2p(object): """Client-side completion machinery. @@ -23,30 +27,25 @@ class ClientCompleter2p(object): dict(text=text, line=line)) # send completion request to kernel # Give the kernel up to 0.5s to respond - msg_matches = None for i in range(5): - if self.km.xreq_channel.was_called(): - msg_xreq = self.km.xreq_channel.get_msg() - if msg["header"]['session'] == msg_xreq["parent_header"]['session'] : - if msg_xreq["content"]["status"] == 'ok' : - if msg_xreq["msg_type"] == "complete_reply" : - msg_matches = msg_xreq["content"]["matches"] - #break - time.sleep(0.1) - return msg_matches + if self.km.xreq_channel.was_called(): + msg_xreq = self.km.xreq_channel.get_msg() + if msg["header"]['session'] == msg_xreq["parent_header"]['session'] and \ + msg_xreq["content"]["status"] == 'ok' and \ + msg_xreq["msg_type"] == "complete_reply" : + return msg_xreq["content"]["matches"] + + time.sleep(0.1) + raise TimeoutError def complete(self, text, state): - if state == 0 : - self.matches = self.complete_request(text) - - if self.matches is None: - self.matches = [] - print('WARNING: Kernel timeout on tab completion.') - #print self.matches + if state == 0: + try: + self.matches = self.complete_request(text) + except TimeoutError: + print('WARNING: Kernel timeout on tab completion.') + try: return self.matches[state] except IndexError: return None - - -