From 447dc20bb90be8d22820321b954748e878bc20e4 2011-12-06 01:40:55 From: Omar Andres Zapata Mesa Date: 2011-12-06 01:40:55 Subject: [PATCH] completer not working fine --- diff --git a/IPython/frontend/terminal/frontend.py b/IPython/frontend/terminal/frontend.py index 9454758..be7f9bd 100755 --- a/IPython/frontend/terminal/frontend.py +++ b/IPython/frontend/terminal/frontend.py @@ -70,9 +70,10 @@ class Frontend(object): self.msg_header = self.km.session.msg_header() self.completer = completer.ClientCompleter(self,self.session,self.request_socket) - rlcompleter.readline.parse_and_bind('tab: complete') - rlcompleter.readline.parse_and_bind('set show-all-if-ambiguous on') rlcompleter.readline.set_completer(self.completer.complete) + rlcompleter.readline.parse_and_bind("tab: complete") + rlcompleter.readline.parse_and_bind('set show-all-if-ambiguous on') + history_path = os.path.expanduser('~/.ipython/history') if os.path.isfile(history_path): rlcompleter.readline.read_history_file(history_path) @@ -131,27 +132,29 @@ class Frontend(object): See parent class :meth:`execute` docstring for full details. """ - msg_id = self.km.xreq_channel.execute(source, hidden) - #timer to debug - time.sleep(0.5) - if self.km.xreq_channel.was_called(): - self.msg_xreq = self.km.xreq_channel.get_msg() - print self.msg_xreq - if self.msg_header["session"] == self.msg_xreq["parent_header"]["session"] : - if self.msg_xreq["content"]["status"] == 'ok' : - if self.msg_xreq["msg_type"] == "complete_reply" : - print self.msg_xreq["content"]["matches"] + self.km.xreq_channel.execute(source, hidden) + self.handle_xreq_channel() + + def handle_xreq_channel(self): + # Give the kernel up to 0.5s to respond + for i in range(5): + if self.km.xreq_channel.was_called(): + self.msg_xreq = self.km.xreq_channel.get_msg() + if self.msg_header["session"] == self.msg_xreq["parent_header"]["session"] : + if self.msg_xreq["content"]["status"] == 'ok' : + if self.msg_xreq["msg_type"] == "complete_reply" : + print self.msg_xreq["content"]["matches"] - if self.msg_xreq["msg_type"] == "execute_reply" : - self.prompt_count = self.msg_xreq["content"]["execution_count"] + if self.msg_xreq["msg_type"] == "execute_reply" : + self.handle_sub_channel() + self.prompt_count = self.msg_xreq["content"]["execution_count"] - self.handle_sub_channel() - else: - print >> sys.stderr, "Error executing: ", source - print >> sys.stderr, "Status in the kernel: ", self.msg_xreq["content"]["status"] - #print msg_xreq - else: - print >> sys.stderr, "Kernel is busy!" + else: + print >> sys.stderr, "Error executing: ",self.msg_xreq ##traceback no implemented yet here + print >> sys.stderr, "Status in the kernel: ", self.msg_xreq["content"]["status"] + break + time.sleep(0.1) + def handle_sub_channel(self): diff --git a/IPython/frontend/terminal/kernelmanager.py b/IPython/frontend/terminal/kernelmanager.py index c685ebf..a95206c 100644 --- a/IPython/frontend/terminal/kernelmanager.py +++ b/IPython/frontend/terminal/kernelmanager.py @@ -18,10 +18,10 @@ class SubSocketChannel2p(SubSocketChannel): self.queue.put(Message(msg)) def get_msg(self): - return self.queue.get() + return self.queue.get(timeout=0.1) def was_called(self): - return not self.queue.empty() + return self.queue.not_empty() class XReqSocketChannel2p(XReqSocketChannel): #--------------------------------------------------------------------------- @@ -29,16 +29,15 @@ class XReqSocketChannel2p(XReqSocketChannel): #--------------------------------------------------------------------------- _msg = None _called = False + queue = Queue(-1) def call_handlers(self, msg): - self._called = True - self._msg = Message(msg) + self.queue.put(Message(msg)) def get_msg(self): - self._called = False - return self._msg + return self.queue.get(timeout=0.1) def was_called(self): - return self._called + return self.queue.not_empty() class RepSocketChannel2p(RepSocketChannel): #---------------------------------------------------------------------------