##// END OF EJS Templates
This feature was discussed in #6123, but it doesn't look like anything was ever incorporated into the IPython Notebook....
This feature was discussed in #6123, but it doesn't look like anything was ever incorporated into the IPython Notebook. Here's a brief overview of the changes: - Display of messages from other clients can be toggled on and off from within a notebook, either using the ``<M-m>e`` keyboard shortcut in the web UI, or through the option in the "Kernel" menu. - notebook.js controls whether messages are displayed through a callback that is invoked from kernel.js when no callbacks are available for a message. - The UI displays ``execute_input`` messages originating from an other clients in new cells at the end of the notebook. Output messages (``execute_result`` et al.) will only be displayed if a cell exists with a matching message ID. Pending design questions: - Should each ``execute_input`` message cause a new cell to be created? - Should new cells be placed at the end of the notebook, or elsewhere? If the latter, what criteria should be followed?

File last commit:

r16535:1b24c44e
r19164:17ac8ca3
Show More
heartbeat.py
68 lines | 2.3 KiB | text/x-python | PythonLexer
Brian Granger
Added heartbeat support.
r2910 """The client and server for a basic ping-pong style heartbeat.
"""
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2008-2011 The IPython Development Team
Brian Granger
Added heartbeat support.
r2910 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Pankaj Pandey
ZMQ heartbeat: catch EINTR exceptions and continue....
r12301 import errno
MinRK
enable IPC transport for kernels...
r7321 import os
MinRK
specify heartbeat port at construction, not in run...
r4500 import socket
Brian Granger
Added heartbeat support.
r2910 from threading import Thread
import zmq
MinRK
avoid executing code in utils.localinterfaces at import time...
r12591 from IPython.utils.localinterfaces import localhost
MinRK
Possible fix for GH-169
r3144
Brian Granger
Added heartbeat support.
r2910 #-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
class Heartbeat(Thread):
"A simple ping-pong style heartbeat that runs in a thread."
MinRK
avoid executing code in utils.localinterfaces at import time...
r12591 def __init__(self, context, addr=None):
if addr is None:
addr = ('tcp', localhost(), 0)
Brian Granger
Added heartbeat support.
r2910 Thread.__init__(self)
self.context = context
MinRK
enable IPC transport for kernels...
r7321 self.transport, self.ip, self.port = addr
MinRK
specify heartbeat port at construction, not in run...
r4500 if self.port == 0:
MinRK
enable IPC transport for kernels...
r7321 if addr[0] == 'tcp':
s = socket.socket()
# '*' means all interfaces to 0MQ, which is '' to socket.socket
s.bind(('' if self.ip == '*' else self.ip, 0))
self.port = s.getsockname()[1]
s.close()
elif addr[0] == 'ipc':
MinRK
fix default heartbeat location when transport is ipc
r9176 self.port = 1
while os.path.exists("%s-%s" % (self.ip, self.port)):
MinRK
enable IPC transport for kernels...
r7321 self.port = self.port + 1
else:
raise ValueError("Unrecognized zmq transport: %s" % addr[0])
MinRK
fix --ip='*' argument in various apps...
r5170 self.addr = (self.ip, self.port)
Brian Granger
Added heartbeat support.
r2910 self.daemon = True
def run(self):
self.socket = self.context.socket(zmq.REP)
MinRK
set linger on every socket I can find...
r16535 self.socket.linger = 1000
MinRK
enable IPC transport for kernels...
r7321 c = ':' if self.transport == 'tcp' else '-'
self.socket.bind('%s://%s' % (self.transport, self.ip) + c + str(self.port))
Pankaj Pandey
ZMQ heartbeat: catch EINTR exceptions and continue....
r12301 while True:
try:
zmq.device(zmq.FORWARDER, self.socket, self.socket)
except zmq.ZMQError as e:
if e.errno == errno.EINTR:
continue
else:
raise
else:
break