##// END OF EJS Templates
Merge pull request #1295 from minrk/btree...
Merge pull request #1295 from minrk/btree Add binary-tree engine interconnect example. This implements a parallel [all]reduce as used in traditional MapReduce scenarios; this is a useful example showing how the IPython.parallel tools can be configured with a different interconnect topology in addition to the default view of N engines connected to 1 controller in a simple star topology.

File last commit:

r5390:c82649ea
r6662:eada8294 merge
Show More
heartbeat.py
48 lines | 1.6 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
#-----------------------------------------------------------------------------
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
MinRK
fix --ip='*' argument in various apps...
r5170 self.ip, self.port = addr
MinRK
specify heartbeat port at construction, not in run...
r4500 if self.port == 0:
s = socket.socket()
MinRK
fix --ip='*' argument in various apps...
r5170 # '*' means all interfaces to 0MQ, which is '' to socket.socket
s.bind(('' if self.ip == '*' else self.ip, 0))
MinRK
specify heartbeat port at construction, not in run...
r4500 self.port = s.getsockname()[1]
s.close()
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
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)