##// END OF EJS Templates
Added pausing to the heartbeat channel.
Brian Granger -
Show More
@@ -515,10 +515,13 b' class HBSocketChannel(ZmqSocketChannel):'
515 515 time_to_dead = 3.0
516 516 socket = None
517 517 poller = None
518 _running = None
519 _pause = None
518 520
519 521 def __init__(self, context, session, address):
520 522 super(HBSocketChannel, self).__init__(context, session, address)
521 523 self._running = False
524 self._pause = False
522 525
523 526 def _create_socket(self):
524 527 self.socket = self.context.socket(zmq.REQ)
@@ -538,6 +541,9 b' class HBSocketChannel(ZmqSocketChannel):'
538 541 # after the sockets are connected.
539 542 time.sleep(2.0)
540 543 while self._running:
544 if self._pause:
545 time.sleep(self.time_to_dead)
546 else:
541 547 since_last_heartbeat = 0.0
542 548 request_time = time.time()
543 549 try:
@@ -584,6 +590,21 b' class HBSocketChannel(ZmqSocketChannel):'
584 590 time.sleep(until_dead)
585 591 break
586 592
593 def pause(self):
594 """Pause the heartbeat."""
595 self._pause = True
596
597 def unpause(self):
598 """Unpause the heartbeat."""
599 self._pause = False
600
601 def is_beating(self):
602 """Is the heartbeat running and not paused."""
603 if self.is_alive() and not self._pause:
604 return True
605 else:
606 return False
607
587 608 def stop(self):
588 609 self._running = False
589 610 super(HBSocketChannel, self).stop()
@@ -646,8 +667,8 b' class KernelManager(HasTraits):'
646 667 # Channel management methods:
647 668 #--------------------------------------------------------------------------
648 669
649 def start_channels(self, xreq=True, sub=True, rep=True, hb=True):
650 """Starts the channels for this kernel.
670 def start_channels(self, xreq=True, sub=True, rep=True):
671 """Starts the channels for this kernel, but not the heartbeat.
651 672
652 673 This will create the channels if they do not exist and then start
653 674 them. If port numbers of 0 are being used (random ports) then you
@@ -660,8 +681,6 b' class KernelManager(HasTraits):'
660 681 self.sub_channel.start()
661 682 if rep:
662 683 self.rep_channel.start()
663 if hb:
664 self.hb_channel.start()
665 684
666 685 def stop_channels(self):
667 686 """Stops all the running channels for this kernel.
@@ -672,16 +691,13 b' class KernelManager(HasTraits):'
672 691 self.sub_channel.stop()
673 692 if self.rep_channel.is_alive():
674 693 self.rep_channel.stop()
675 if self.hb_channel.is_alive():
676 self.hb_channel.stop()
677 694
678 695 @property
679 696 def channels_running(self):
680 697 """Are any of the channels created and running?"""
681 698 return self.xreq_channel.is_alive() \
682 699 or self.sub_channel.is_alive() \
683 or self.rep_channel.is_alive() \
684 or self.hb_channel.is_alive()
700 or self.rep_channel.is_alive()
685 701
686 702 #--------------------------------------------------------------------------
687 703 # Kernel process management methods:
General Comments 0
You need to be logged in to leave comments. Login now