##// END OF EJS Templates
restore msg_id/msg_type aliases in top level of msg dict...
restore msg_id/msg_type aliases in top level of msg dict msg_id/type must be stored in the header, as only the header/parent/content are actually sent over the wire. But the msg_id and msg_type should remain as aliases in the top-level msg dict, for logic and 0.11 compatibility. * docs and tests updated to match.

File last commit:

r4500:79472ea0
r4711:2e95bace
Show More
heartbeat.py
49 lines | 1.5 KiB | text/x-python | PythonLexer
Brian Granger
Added heartbeat support.
r2910 """The client and server for a basic ping-pong style heartbeat.
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2010 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
MinRK
specify heartbeat port at construction, not in run...
r4500 import socket
Brian Granger
Added heartbeat support.
r2910 import sys
from threading import Thread
import zmq
MinRK
Possible fix for GH-169
r3144 from IPython.utils.localinterfaces import LOCALHOST
Brian Granger
Added heartbeat support.
r2910 #-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
class Heartbeat(Thread):
"A simple ping-pong style heartbeat that runs in a thread."
MinRK
Possible fix for GH-169
r3144 def __init__(self, context, addr=(LOCALHOST, 0)):
Brian Granger
Added heartbeat support.
r2910 Thread.__init__(self)
self.context = context
self.addr = addr
self.ip = addr[0]
self.port = addr[1]
MinRK
specify heartbeat port at construction, not in run...
r4500 if self.port == 0:
s = socket.socket()
s.bind(self.addr)
self.port = s.getsockname()[1]
s.close()
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
specify heartbeat port at construction, not in run...
r4500 self.socket.bind('tcp://%s:%i' % self.addr)
Brian Granger
Added heartbeat support.
r2910 zmq.device(zmq.FORWARDER, self.socket, self.socket)