##// END OF EJS Templates
Merge branch 'newkernel' into trunk with all new Qt console work....
Merge branch 'newkernel' into trunk with all new Qt console work. This provides a new main script, ipython-qtconsole, that offers a rich Qt widget capable of multiline editing, inline plots, html help and much more. This branch was developed over the last two months mostly by Evan Patterson, Brian Granger and Fernando Perez, thanks to the support of Enthought, Inc. The code is now in a good prototype stage, and it's being merged into trunk where further work, polishing and stabilization will take place.

File last commit:

r2910:e4350871
r3070:95e9a8d0 merge
Show More
heartbeat.py
43 lines | 1.4 KiB | text/x-python | PythonLexer
"""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
#-----------------------------------------------------------------------------
import sys
from threading import Thread
import zmq
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
class Heartbeat(Thread):
"A simple ping-pong style heartbeat that runs in a thread."
def __init__(self, context, addr=('127.0.0.1', 0)):
Thread.__init__(self)
self.context = context
self.addr = addr
self.ip = addr[0]
self.port = addr[1]
self.daemon = True
def run(self):
self.socket = self.context.socket(zmq.REP)
if self.port == 0:
self.port = self.socket.bind_to_random_port('tcp://%s' % self.ip)
else:
self.socket.bind('tcp://%s:%i' % self.addr)
zmq.device(zmq.FORWARDER, self.socket, self.socket)