##// END OF EJS Templates
Merge pull request #5396 from ivanov/fix-5363...
Merge pull request #5396 from ivanov/fix-5363 prevent saving of partially loaded notebooks

File last commit:

r13354:5d199385
r15995:41452895 merge
Show More
channels.py
82 lines | 2.5 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
#-----------------------------------------------------------------------------
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
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)
Thomas Kluyver
Update imports for Python 3...
r13354 self._in_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))
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? """
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