##// END OF EJS Templates
Add pexpect version 2.3 (revision 507) to IPython.external....
Add pexpect version 2.3 (revision 507) to IPython.external. We will only use our copy if the system-installed one isn't found. This lets us run the core of ipython on top of the stdlib, while having far better subprocess control than we otherwise would on posix. On windows, pexpect doesn't exist, so the subprocess situation is still not ideal. pexpect is MIT-licensed. For more information on pexpect: http://www.noah.org/wiki/Pexpect

File last commit:

r2693:a6cdb64c
r2906:9c141886
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