##// END OF EJS Templates
Multiple improvements to tab completion....
Multiple improvements to tab completion. I refactored the API quite a bit, to retain readline compatibility but make it more independent of readline. There's still more to do in cleaning up our init_readline() method, but now the completer objects have separate rlcomplete() and complete() methods. The former uses the quirky readline API with a state flag, while the latter is stateless, takes only text information, and is more suitable for GUIs and other frontends to call programatically. Made other minor fixes to ensure the test suite passes in full. While all this code is a bit messy, we're getting in the direction of the APIs we need in the long run.

File last commit:

r2693:a6cdb64c
r2839:8cff4913
Show More
blockingkernelmanager.py
43 lines | 1.2 KiB | text/x-python | PythonLexer
/ IPython / zmq / blockingkernelmanager.py
from kernelmanager import SubSocketChannel
from Queue import Queue, Empty
class MsgNotReady(Exception):
pass
class BlockingSubSocketChannel(SubSocketChannel):
def __init__(self, context, session, address=None):
super(BlockingSubSocketChannel, self).__init__(context, session, address)
self._in_queue = Queue()
def call_handlers(self, msg):
self._in_queue.put(msg)
def msg_ready(self):
"""Is there a message that has been received?"""
if self._in_queue.qsize() == 0:
return False
else:
return True
def get_msg(self, block=True, timeout=None):
"""Get a message if there is one that is ready."""
try:
msg = self.in_queue.get(block, timeout)
except Empty:
raise MsgNotReady('No message has been received.')
else:
return msg
def get_msgs(self):
"""Get all messages that are currently ready."""
msgs = []
while True:
try:
msg = self.get_msg(block=False)
except MsgNotReady:
break
else:
msgs.append(msg)
return msgs