def terminate_heartbeat(self):
        """
        **Purpose**: Method to terminate the heartbeat thread. This method is 
        blocking as it waits for the heartbeat thread to terminate (aka join).

        This is the last method that is executed from the TaskManager and
        hence closes the profiler.
        """

        try:

            if self._hb_thread:

                self._hb_terminate.set()

                if self.check_heartbeat():
                    self._hb_thread.join()

                self._hb_thread = None

                self._logger.info('Hearbeat thread terminated')

                self._prof.prof('heartbeat thread terminated', uid=self._uid)

                # We close in the heartbeat because it ends after the tmgr process
                self._prof.close()

        except Exception, ex:
            self._logger.exception('Could not terminate heartbeat thread')
            raise

        finally:

            if not (self.check_heartbeat() or self.check_manager()):

                mq_connection = pika.BlockingConnection(pika.ConnectionParameters(host=self._mq_hostname, port=self._port))
                mq_channel = mq_connection.channel()

                # To respond to heartbeat - get request from rpc_queue
                mq_channel.queue_delete(queue=self._hb_response_q)
                mq_channel.queue_delete(queue=self._hb_request_q)

                mq_connection.close()
def terminate_heartbeat ( self ) : try : if self . _hb_thread : self . _hb_terminate . set ( ) if self . check_heartbeat ( ) : self . _hb_thread . join ( ) self . _hb_thread = None self . _logger . info ( 'Hearbeat thread terminated' ) self . _prof . prof ( 'heartbeat thread terminated' , uid = self . _uid ) self . _prof . close ( ) except Exception , ex : self . _logger . exception ( 'Could not terminate heartbeat thread' ) raise finally : if not ( self . check_heartbeat ( ) or self . check_manager ( ) ) : mq_connection = pika . BlockingConnection ( pika . ConnectionParameters ( host = self . _mq_hostname , port = self . _port ) ) mq_channel = mq_connection . channel ( ) mq_channel . queue_delete ( queue = self . _hb_response_q ) mq_channel . queue_delete ( queue = self . _hb_request_q ) mq_connection . close ( )
**Purpose**: Method to terminate the heartbeat thread. This method is 
        blocking as it waits for the heartbeat thread to terminate (aka join).

        This is the last method that is executed from the TaskManager and
        hence closes the profiler.