Show More
@@ -458,7 +458,7 b' class IOPubHandler(AuthenticatedZMQStreamHandler):' | |||||
458 | except: |
|
458 | except: | |
459 | pass |
|
459 | pass | |
460 | finally: |
|
460 | finally: | |
461 |
self. |
|
461 | self.stop_hb() | |
462 |
|
462 | |||
463 | def beat_received(msg): |
|
463 | def beat_received(msg): | |
464 | self._kernel_alive = True |
|
464 | self._kernel_alive = True | |
@@ -466,12 +466,21 b' class IOPubHandler(AuthenticatedZMQStreamHandler):' | |||||
466 | self.hb_stream.on_recv(beat_received) |
|
466 | self.hb_stream.on_recv(beat_received) | |
467 | loop = ioloop.IOLoop.instance() |
|
467 | loop = ioloop.IOLoop.instance() | |
468 | self._hb_periodic_callback = ioloop.PeriodicCallback(ping_or_dead, self.time_to_dead*1000, loop) |
|
468 | self._hb_periodic_callback = ioloop.PeriodicCallback(ping_or_dead, self.time_to_dead*1000, loop) | |
469 |
loop.add_timeout(time.time()+self.first_beat, self._ |
|
469 | loop.add_timeout(time.time()+self.first_beat, self._really_start_hb) | |
470 | self._beating= True |
|
470 | self._beating= True | |
|
471 | ||||
|
472 | def _really_start_hb(self): | |||
|
473 | """callback for delayed heartbeat start | |||
|
474 | ||||
|
475 | Only start the hb loop if we haven't been closed during the wait. | |||
|
476 | """ | |||
|
477 | if self._beating and not self.hb_stream.closed(): | |||
|
478 | self._hb_periodic_callback.start() | |||
471 |
|
479 | |||
472 | def stop_hb(self): |
|
480 | def stop_hb(self): | |
473 | """Stop the heartbeating and cancel all related callbacks.""" |
|
481 | """Stop the heartbeating and cancel all related callbacks.""" | |
474 | if self._beating: |
|
482 | if self._beating: | |
|
483 | self._beating = False | |||
475 | self._hb_periodic_callback.stop() |
|
484 | self._hb_periodic_callback.stop() | |
476 | if not self.hb_stream.closed(): |
|
485 | if not self.hb_stream.closed(): | |
477 | self.hb_stream.on_recv(None) |
|
486 | self.hb_stream.on_recv(None) |
General Comments 0
You need to be logged in to leave comments.
Login now