##// END OF EJS Templates
add pandoc to install docs
add pandoc to install docs

File last commit:

r10285:5e1e98c2
r11491:28fd0311
Show More
channels.py
79 lines | 2.4 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.
"""
#-----------------------------------------------------------------------------
MinRK
split KernelManager into KernelManager + KernelClient
r10285 # Copyright (C) 2013 The IPython Development Team
Fernando Perez
Rework messaging to better conform to our spec....
r2926 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING.txt, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Brian Granger
Creating an ABC for kernel managers and channels.
r9121 import Queue
MinRK
split KernelManager into KernelManager + KernelClient
r10285 from IPython.kernel.channels import IOPubChannel, HBChannel, \
Brian Granger
Cleanup naming and organization of channels....
r9120 ShellChannel, StdInChannel
Brian Granger
Added initial draft of blockingkernelmanager.py.
r2693
Fernando Perez
Rework messaging to better conform to our spec....
r2926 #-----------------------------------------------------------------------------
epatters
Refactor kernel managers in preparation for the EmbeddedKernel.
r8408 # Blocking kernel manager
Fernando Perez
Rework messaging to better conform to our spec....
r2926 #-----------------------------------------------------------------------------
Brian Granger
Added initial draft of blockingkernelmanager.py.
r2693
Brian Granger
Cleanup naming and organization of channels....
r9120
class BlockingChannelMixin(object):
MinRK
relocate redundantly-named kernel files...
r10283
Brian Granger
Cleanup naming and organization of channels....
r9120 def __init__(self, *args, **kwds):
super(BlockingChannelMixin, self).__init__(*args, **kwds)
self._in_queue = Queue.Queue()
MinRK
relocate redundantly-named kernel files...
r10283
Brian Granger
Cleanup naming and organization of channels....
r9120 def call_handlers(self, msg):
self._in_queue.put(msg)
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. """
MinRK
never use Queue.get(timeout=None)...
r9358 if timeout is None:
# Queue.get(timeout=None) has stupid uninteruptible
# behavior, so wait for a week instead
timeout = 604800
Brian Granger
Cleanup naming and organization of channels....
r9120 return self._in_queue.get(block, timeout)
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))
except Queue.Empty:
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? """
return not self._in_queue.empty()
class BlockingIOPubChannel(BlockingChannelMixin, IOPubChannel):
epatters
Refactor kernel managers in preparation for the EmbeddedKernel.
r8408 pass
Fernando Perez
Rework messaging to better conform to our spec....
r2926
Brian Granger
Cleanup naming and organization of channels....
r9120
class BlockingShellChannel(BlockingChannelMixin, ShellChannel):
epatters
Refactor kernel managers in preparation for the EmbeddedKernel.
r8408 pass
Fernando Perez
Rework messaging to better conform to our spec....
r2926
Brian Granger
Cleanup naming and organization of channels....
r9120
class BlockingStdInChannel(BlockingChannelMixin, StdInChannel):
epatters
Refactor kernel managers in preparation for the EmbeddedKernel.
r8408 pass
Fernando Perez
Rework messaging to better conform to our spec....
r2926
Brian Granger
Cleanup naming and organization of channels....
r9120
class BlockingHBChannel(HBChannel):
MinRK
relocate redundantly-named kernel files...
r10283
MinRK
Fixes to the heartbeat channel...
r5614 # This kernel needs quicker monitoring, shorten to 1 sec.
# less than 0.5s is unreliable, and will get occasional
# false reports of missed beats.
time_to_dead = 1.
Fernando Perez
Rework messaging to better conform to our spec....
r2926
def call_handlers(self, since_last_heartbeat):
epatters
Refactor kernel managers in preparation for the EmbeddedKernel.
r8408 """ Pause beating on missed heartbeat. """
epatters
Add missing msg queue + comment out debug printing in BlockingKernelManager.
r3825 pass