From 5efa769d48e794f98b0e5ef096439d1569ebc89c 2014-09-04 21:45:04 From: Thomas Kluyver Date: 2014-09-04 21:45:04 Subject: [PATCH] Merge pull request #6363 from minrk/debug-heartbeat add secondary `debug` flag for heartbeats --- diff --git a/IPython/kernel/restarter.py b/IPython/kernel/restarter.py index 6dec73e..d34ce61 100644 --- a/IPython/kernel/restarter.py +++ b/IPython/kernel/restarter.py @@ -6,31 +6,27 @@ restarts the kernel if it dies. It is an incomplete base class, and must be subclassed. """ -#----------------------------------------------------------------------------- -# Copyright (C) 2013 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 -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. from IPython.config.configurable import LoggingConfigurable from IPython.utils.traitlets import ( Instance, Float, Dict, Bool, Integer, ) -#----------------------------------------------------------------------------- -# Code -#----------------------------------------------------------------------------- class KernelRestarter(LoggingConfigurable): """Monitor and autorestart a kernel.""" kernel_manager = Instance('IPython.kernel.KernelManager') - + + debug = Bool(False, config=True, + help="""Whether to include every poll event in debugging output. + + Has to be set explicitly, because there will be *a lot* of output. + """ + ) + time_to_dead = Float(3.0, config=True, help="""Kernel heartbeat interval in seconds.""" ) @@ -87,7 +83,8 @@ class KernelRestarter(LoggingConfigurable): self.log.error("KernelRestarter: %s callback %r failed", event, callback, exc_info=True) def poll(self): - self.log.debug('Polling kernel...') + if self.debug: + self.log.debug('Polling kernel...') if not self.kernel_manager.is_alive(): if self._restarting: self._restart_count += 1 diff --git a/IPython/parallel/controller/heartmonitor.py b/IPython/parallel/controller/heartmonitor.py index f025e4c..3692e5e 100755 --- a/IPython/parallel/controller/heartmonitor.py +++ b/IPython/parallel/controller/heartmonitor.py @@ -2,17 +2,10 @@ """ A multi-heart Heartbeat system using PUB and ROUTER sockets. pings are sent out on the PUB, and hearts are tracked based on their DEALER identities. - -Authors: - -* Min RK """ -#----------------------------------------------------------------------------- -# Copyright (C) 2010-2011 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. -#----------------------------------------------------------------------------- + +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. from __future__ import print_function import time @@ -24,7 +17,7 @@ from zmq.eventloop import ioloop, zmqstream from IPython.config.configurable import LoggingConfigurable from IPython.utils.py3compat import str_to_bytes -from IPython.utils.traitlets import Set, Instance, CFloat, Integer, Dict +from IPython.utils.traitlets import Set, Instance, CFloat, Integer, Dict, Bool from IPython.parallel.util import log_errors @@ -69,7 +62,13 @@ class HeartMonitor(LoggingConfigurable): pingstream: a PUB stream pongstream: an ROUTER stream period: the period of the heartbeat in milliseconds""" - + + debug = Bool(False, config=True, + help="""Whether to include every heartbeat in debugging output. + + Has to be set explicitly, because there will be *a lot* of output. + """ + ) period = Integer(3000, config=True, help='The frequency at which the Hub pings the engines for heartbeats ' '(in ms)', @@ -121,7 +120,8 @@ class HeartMonitor(LoggingConfigurable): toc = time.time() self.lifetime += toc-self.tic self.tic = toc - self.log.debug("heartbeat::sending %s", self.lifetime) + if self.debug: + self.log.debug("heartbeat::sending %s", self.lifetime) goodhearts = self.hearts.intersection(self.responses) missed_beats = self.hearts.difference(goodhearts) newhearts = self.responses.difference(goodhearts) @@ -181,7 +181,8 @@ class HeartMonitor(LoggingConfigurable): last = str_to_bytes(str(self.last_ping)) if msg[1] == current: delta = time.time()-self.tic - # self.log.debug("heartbeat::heart %r took %.2f ms to respond"%(msg[0], 1000*delta)) + if self.debug: + self.log.debug("heartbeat::heart %r took %.2f ms to respond", msg[0], 1000*delta) self.responses.add(msg[0]) elif msg[1] == last: delta = time.time()-self.tic + (self.lifetime-self.last_ping)