##// END OF EJS Templates
Remove Qt console package_data from setup...
Remove Qt console package_data from setup We should remember this when the ipython_qtconsole package gets its own setup. Closes gh-8140

File last commit:

r19344:a060c26a
r20864:f84c26a2
Show More
channels.py
92 lines | 2.3 KiB | text/x-python | PythonLexer
MinRK
split KernelManager into KernelManager + KernelClient
r10285 """Blocking channels
Fernando Perez
Rework messaging to better conform to our spec....
r2926
Useful for test suites and blocking terminal interfaces.
"""
Thomas Kluyver
Implement blocking channels without Python threads
r19208 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Thomas Kluyver
Update imports for Python 3...
r13354 try:
from queue import Queue, Empty # Py 3
except ImportError:
from Queue import Queue, Empty # Py 2
Brian Granger
Creating an ABC for kernel managers and channels.
r9121
Brian Granger
Added initial draft of blockingkernelmanager.py.
r2693
Thomas Kluyver
Implement blocking channels without Python threads
r19208 class ZMQSocketChannel(object):
Thomas Kluyver
Get rid of address property on channels
r19225 """A ZMQ socket in a simple blocking API"""
Thomas Kluyver
Implement blocking channels without Python threads
r19208 session = None
socket = None
stream = None
_exiting = False
proxy_methods = []
Brian Granger
Cleanup naming and organization of channels....
r9120
Thomas Kluyver
Share an IOLoop among Qt channels, rather than one each
r19224 def __init__(self, socket, session, loop=None):
Thomas Kluyver
Implement blocking channels without Python threads
r19208 """Create a channel.
MinRK
relocate redundantly-named kernel files...
r10283
Thomas Kluyver
Implement blocking channels without Python threads
r19208 Parameters
----------
Thomas Kluyver
Share an IOLoop among Qt channels, rather than one each
r19224 socket : :class:`zmq.Socket`
The ZMQ socket to use.
Thomas Kluyver
Implement blocking channels without Python threads
r19208 session : :class:`session.Session`
The session to use.
Thomas Kluyver
Share an IOLoop among Qt channels, rather than one each
r19224 loop
Unused here, for other implementations
Thomas Kluyver
Implement blocking channels without Python threads
r19208 """
super(ZMQSocketChannel, self).__init__()
MinRK
relocate redundantly-named kernel files...
r10283
Thomas Kluyver
Move ZMQ socket creation out of channels
r19217 self.socket = socket
Thomas Kluyver
Implement blocking channels without Python threads
r19208 self.session = session
def _recv(self, **kwargs):
msg = self.socket.recv_multipart(**kwargs)
ident,smsg = self.session.feed_identities(msg)
return self.session.deserialize(smsg)
MinRK
relocate redundantly-named kernel files...
r10283
Brian Granger
Cleanup naming and organization of channels....
r9120 def get_msg(self, block=True, timeout=None):
""" Gets a message if there is one that is ready. """
Thomas Kluyver
Implement blocking channels without Python threads
r19208 if block:
if timeout is not None:
timeout *= 1000 # seconds to ms
ready = self.socket.poll(timeout)
else:
ready = self.socket.poll(timeout=0)
if ready:
return self._recv()
else:
raise Empty
MinRK
relocate redundantly-named kernel files...
r10283
Brian Granger
Cleanup naming and organization of channels....
r9120 def get_msgs(self):
""" Get all messages that are currently ready. """
msgs = []
while True:
try:
msgs.append(self.get_msg(block=False))
Thomas Kluyver
Update imports for Python 3...
r13354 except Empty:
Brian Granger
Cleanup naming and organization of channels....
r9120 break
return msgs
MinRK
relocate redundantly-named kernel files...
r10283
Brian Granger
Cleanup naming and organization of channels....
r9120 def msg_ready(self):
""" Is there a message that has been received? """
Thomas Kluyver
Implement blocking channels without Python threads
r19208 return bool(self.socket.poll(timeout=0))
def close(self):
if self.socket is not None:
try:
self.socket.close(linger=0)
except Exception:
pass
self.socket = None
stop = close
def is_alive(self):
return (self.socket is not None)
Thomas Kluyver
Rename _queue_send to send
r19344 def send(self, msg):
Thomas Kluyver
Implement blocking channels without Python threads
r19208 """Pass a message to the ZMQ socket to send
"""
self.session.send(self.socket, msg)
Thomas Kluyver
Move ZMQ socket creation out of channels
r19217 def start(self):
pass